Documentation ¶
Index ¶
- func Locals(args ...any) map[string]any
- type LayoutContextKey
- type Templates
- func (t *Templates) AddDynamicBlockToFuncMap()
- func (t *Templates) AddFuncMapHelpers()
- func (t *Templates) AddLocalsToFuncMap()
- func (t *Templates) AddTrustedHTMLToFuncMap()
- func (t *Templates) ExecuteTemplate(w io.Writer, r *http.Request, templateName string, data interface{}) error
- func (t *Templates) ExecuteTemplateAsText(r *http.Request, templateName string, data interface{}) (string, error)
- func (t *Templates) GetParsedTemplates() []string
- func (t *Templates) HandlerRenderWithData(templateName string, data interface{}) func(w http.ResponseWriter, r *http.Request)
- func (t *Templates) HandlerRenderWithDataFromContext(templateName string, contextKey interface{}) func(w http.ResponseWriter, r *http.Request)
- func (t *Templates) MustParseTemplates()
- func (t *Templates) ParseTemplates() error
- func (t *Templates) RenderBlockAsHTMLString(blockname string, payload interface{}) (safehtml.HTML, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type LayoutContextKey ¶
type LayoutContextKey struct{}
LayoutContextKey is the key for getting the layout string out of the context
type Templates ¶
type Templates struct { AlwaysReloadAndParseTemplates bool DefaultLayout string TemplateFileExtension string TemplatesPath template.TrustedSource LayoutsPath string PagesPath string BlocksPath string AddHeadlessCMSFuncMapHelpers bool // contains filtered or unexported fields }
func New ¶
New return new Templates with default configs and templates functions to support headless cms
func (*Templates) AddDynamicBlockToFuncMap ¶
func (t *Templates) AddDynamicBlockToFuncMap()
AddDynamicBlockToFuncMap adds 'd_block' to the FuncMap which allows to render blocks from variables dynamically set Rob doesn't like, we add it anyway because we like headless cms https://stackoverflow.com/questions/28830543/how-to-use-a-field-of-struct-or-variable-value-as-template-name
func (*Templates) AddFuncMapHelpers ¶
func (t *Templates) AddFuncMapHelpers()
func (*Templates) AddLocalsToFuncMap ¶
func (t *Templates) AddLocalsToFuncMap()
func (*Templates) AddTrustedHTMLToFuncMap ¶
func (t *Templates) AddTrustedHTMLToFuncMap()
func (*Templates) ExecuteTemplate ¶
func (t *Templates) ExecuteTemplate(w io.Writer, r *http.Request, templateName string, data interface{}) error
ExecuteTemplate renders the template specified by name (layout:page or just page)
func (*Templates) ExecuteTemplateAsText ¶
func (*Templates) GetParsedTemplates ¶
func (*Templates) HandlerRenderWithData ¶
func (t *Templates) HandlerRenderWithData(templateName string, data interface{}) func(w http.ResponseWriter, r *http.Request)
HandlerRenderWithData returns a Handler function which only renders the template
func (*Templates) HandlerRenderWithDataFromContext ¶
func (t *Templates) HandlerRenderWithDataFromContext(templateName string, contextKey interface{}) func(w http.ResponseWriter, r *http.Request)
HandlerRenderWithDataFromContext returns a Handler function which only renders the template and uses data from context
func (*Templates) MustParseTemplates ¶
func (t *Templates) MustParseTemplates()
MustParseTemplates goes fatal if there is an error
func (*Templates) ParseTemplates ¶
ParseTemplates reads all html files and freshly compiles the templates