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 PrintTemplates()
- 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) 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) 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 map[string]interface{}
Helper functions available in templates
var Production bool
Production is true if this server is running in production mode
var Templates map[string]parser.Template
The template sets, loaded on startup for production and on every request for development
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, and assigns them to the package variable Templates
func PrintTemplates ¶
func PrintTemplates()
PrintTemplates prints out our list of templates for debug
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
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 |