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) 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) 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 Helpers parser.FuncMap
Helpers is a list of functions available in templates
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 NB if you change helper functions the templates must be reloaded at least once afterwards
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 NewWithPath ¶
func NewWithPath(p string, w http.ResponseWriter) *Renderer
NewWithPath creates a new Renderer with a path and an http.ResponseWriter
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) 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 |