Documentation
¶
Overview ¶
Package view provides methods for rendering templates, and helper functions for golang views
Index ¶
- Variables
- func DefaultHelpers() parser.FuncMap
- func LoadTemplates() error
- func LoadTemplatesAtPaths(paths []string, helpers parser.FuncMap) error
- func PrintTemplates()
- func ReloadTemplates() error
- type RenderContext
- type Renderer
- func (r *Renderer) AddKey(key string, value interface{}) *Renderer
- func (r *Renderer) CacheKey(key string)
- func (r *Renderer) Context(c map[string]interface{}) *Renderer
- func (r *Renderer) Format(format string) *Renderer
- func (r *Renderer) HTML(content string) *Renderer
- func (r *Renderer) Header(k, v string) *Renderer
- func (r *Renderer) Layout(layout string) *Renderer
- func (r *Renderer) Path(p string) *Renderer
- func (r *Renderer) Render() error
- func (r *Renderer) RenderToString() (string, error)
- func (r *Renderer) RenderToStringWithLayout() (string, error)
- func (r *Renderer) Response() error
- func (r *Renderer) SendFile(p string) error
- func (r *Renderer) Status(status int) *Renderer
- func (r *Renderer) Template(template string) *Renderer
- func (r *Renderer) Text(content string) *Renderer
Constants ¶
This section is empty.
Variables ¶
var AuthenticityContext = &ctxKey{authenticityKey}
AuthenticityContext is used as a key to save request authenticity tokens
var Helpers parser.FuncMap
Helpers is a list of functions available in templates
var LanguageContext = &ctxKey{languageKey}
LanguageContext is used as a key to save request lang
var Production bool
Production is true if this server is running in production mode
Functions ¶
func DefaultHelpers ¶
DefaultHelpers returns a default set of helpers for the app, which can then be extended/replaced. Helper functions may not be changed after LoadTemplates is called, as reloading is required if they change.
func LoadTemplates ¶
func LoadTemplates() error
LoadTemplates loads our templates from ./src, and assigns them to the package variable Templates This function is deprecated and will be removed, use LoadTemplatesAtPaths instead
func LoadTemplatesAtPaths ¶ added in v1.4.1
LoadTemplatesAtPaths loads our templates given the paths provided
func PrintTemplates ¶
func PrintTemplates()
PrintTemplates prints out our list of templates for debug
func ReloadTemplates ¶ added in v1.4.1
func ReloadTemplates() error
ReloadTemplates reloads the templates for our scanner
Types ¶
type RenderContext ¶
type RenderContext interface { Path() string RenderContext() map[string]interface{} Writer() http.ResponseWriter }
RenderContext is the type passed in to New, which helps construct the rendering view Alternatively, you can use NewWithPath, which doesn't require a RenderContext
type Renderer ¶
type Renderer struct {
// contains filtered or unexported fields
}
Renderer is a view which is set up on each request and renders the response to its writer
func NewRenderer ¶ added in v1.5.3
func NewRenderer(w http.ResponseWriter, r *http.Request) *Renderer
NewRenderer returns a new renderer for this request.
func NewWithPath ¶
func NewWithPath(p string, w http.ResponseWriter) *Renderer
NewWithPath creates a new Renderer with a path and an http.ResponseWriter
func (*Renderer) CacheKey ¶ added in v1.5.3
CacheKey sets the Cache-Control and Etag headers on the response using the CacheKey() from the Cacher passed in
func (*Renderer) Path ¶
Path sets the request path on the renderer (used for choosing a default template)
func (*Renderer) RenderToString ¶
RenderToString renders our template into layout using our context and return a string
func (*Renderer) RenderToStringWithLayout ¶ added in v1.4.2
RenderToStringWithLayout renders our template into layout using our context and return a string
func (*Renderer) Response ¶ added in v1.5.3
Response renders our template into layout using our context and write out to writer Response is an alternative name for Render so that we can call render.Response(), it may replace it eventually.
func (*Renderer) SendFile ¶ added in v1.5.1
SendFile writes the file at the given path out to our writer it assumes the appropriate headers have been set first (Content-Type, Content-Disposition) e.g.:
view.Header("Content-type", "application/pdf") view.Header("Content-Disposition", "attachment; filename='myfile.pdf'") view.SendFile(mypath)
Directories
¶
Path | Synopsis |
---|---|
Package parser defines an interface for parsers which the base template conforms to Package parser defines an interface for parsers (creating templates) and templates (rendering content), and defines a base template type which conforms to both interfaces and can be included in any templates
|
Package parser defines an interface for parsers which the base template conforms to Package parser defines an interface for parsers (creating templates) and templates (rendering content), and defines a base template type which conforms to both interfaces and can be included in any templates |
Package translation provides a simple in-memory translation service - it may soon be renamed translate
|
Package translation provides a simple in-memory translation service - it may soon be renamed translate |