templatehelpers.go 957 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package templatehelpers
  2. import (
  3. "github.com/kataras/iris"
  4. "strings"
  5. _ "fmt"
  6. )
  7. // TODO outsource this and down to main template handler?
  8. // -> no ShowError/ShowNotification needed anymore?
  9. func ShowError(ctx *iris.Context) {
  10. params := ctx.Get("params").(map[string]string)
  11. ctx.Render(params["reqDir"] + "_box.html", params)
  12. }
  13. func ShowNotification(ctx *iris.Context) {
  14. params := ctx.Get("params").(map[string]string)
  15. ctx.Render(params["reqDir"] + "_box.html", params)
  16. }
  17. func InitPageParams(ctx *iris.Context) {
  18. var params map[string]string
  19. params = make(map[string]string)
  20. loc := strings.TrimLeft(ctx.RequestPath(false), "/")
  21. if loc == "" { // if requesting / -> home
  22. loc = "home"
  23. }
  24. params["reqDir"] = loc
  25. ctx.Set("params", params)
  26. ctx.Next()
  27. }
  28. func UpdatePageParam(ctx *iris.Context, key string, value string) {
  29. params := ctx.Get("params").(map[string]string)
  30. params[key] = value
  31. ctx.Set("params", params)
  32. }