diff options
Diffstat (limited to 'pkg/context/context.go')
-rw-r--r-- | pkg/context/context.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/pkg/context/context.go b/pkg/context/context.go index fa4ed16e..1457deec 100644 --- a/pkg/context/context.go +++ b/pkg/context/context.go @@ -41,6 +41,23 @@ type Context struct { Org *Organization } +// Title sets "Title" field in template data. +func (c *Context) Title(locale string) { + c.Data["Title"] = c.Tr(locale) +} + +// PageIs sets "PageIsxxx" field in template data. +func (c *Context) PageIs(name string) { + c.Data["PageIs"+name] = true +} + +// FormErr sets "Err_xxx" field in template data. +func (c *Context) FormErr(names ...string) { + for i := range names { + c.Data["Err_"+names[i]] = true + } +} + // UserID returns ID of current logged in user. // It returns 0 if visitor is anonymous. func (c *Context) UserID() int64 { @@ -96,6 +113,12 @@ func (c *Context) JSONSuccess(data interface{}) { c.JSON(http.StatusOK, data) } +// SubURLRedirect responses redirection wtih given location and status. +// It prepends setting.AppSubURL to the location string. +func (c *Context) SubURLRedirect(location string, status ...int) { + c.Redirect(setting.AppSubURL + location) +} + // RenderWithErr used for page has form validation but need to prompt error to users. func (ctx *Context) RenderWithErr(msg, tpl string, f interface{}) { if f != nil { |