package tplimpl
import "github.com/gohugoio/hugo/tpl/tplimpl"
Index ¶
- Constants
- type Category
- type ParseConfig
- type ParseInfo
- type PathTemplateDescriptor
- type SiteOptions
- type StoreOptions
- type SubCategory
- type TemplInfo
- func (ti *TemplInfo) Base() tpl.CurrentTemplateInfoCommonOps
- func (ti *TemplInfo) BaseVariantsSeq() iter.Seq[*TemplWithBaseApplied]
- func (ti *TemplInfo) Filename() string
- func (t *TemplInfo) GetIdentity() identity.Identity
- func (t *TemplInfo) IdentifierBase() string
- func (t *TemplInfo) IsProbablyDependency(other identity.Identity) bool
- func (t *TemplInfo) IsProbablyDependent(other identity.Identity) bool
- func (ti *TemplInfo) Name() string
- func (ti *TemplInfo) Prepare() (*texttemplate.Template, error)
- func (ti *TemplInfo) String() string
- func (ti *TemplInfo) SubCategory() SubCategory
- type TemplWithBaseApplied
- type TemplateDescriptor
- type TemplateQuery
- type TemplateStore
- func NewStore(opts StoreOptions, siteOpts SiteOptions) (*TemplateStore, error)
- func (t *TemplateStore) ExecuteWithContext(ctx context.Context, ti *TemplInfo, wr io.Writer, data any) error
- func (s *TemplateStore) FindAllBaseTemplateCandidates(overlayKey string, desc TemplateDescriptor) []keyTemplateInfo
- func (t *TemplateStore) GetFunc(name string) (reflect.Value, bool)
- func (s *TemplateStore) GetIdentity(p string) identity.Identity
- func (s *TemplateStore) HasTemplate(templatePath string) bool
- func (t *TemplateStore) LookupByPath(templatePath string) *TemplInfo
- func (s *TemplateStore) LookupPagesLayout(q TemplateQuery) *TemplInfo
- func (s *TemplateStore) LookupPartial(pth string) *TemplInfo
- func (s *TemplateStore) LookupShortcode(q TemplateQuery) *TemplInfo
- func (s *TemplateStore) NewFromOpts() (*TemplateStore, error)
- func (s *TemplateStore) PrintDebug(prefix string, category Category, w io.Writer)
- func (s *TemplateStore) RefreshFiles(include func(fi hugofs.FileMetaInfo) bool) error
- func (t *TemplateStore) TextLookup(name string) *TemplInfo
- func (t *TemplateStore) TextParse(name, tpl string) (*TemplInfo, error)
- func (t *TemplateStore) UnusedTemplates() []*TemplInfo
- func (s TemplateStore) WithSiteOpts(opts SiteOptions) *TemplateStore
- type TemplateStoreProvider
- type TextTemplatHandler
Constants ¶
const TemplateVersion = 2
Increments on breaking changes.
Types ¶
type Category ¶
type Category int
const ( CategoryLayout Category = iota + 1 CategoryBaseof CategoryMarkup CategoryShortcode CategoryPartial // Internal categories CategoryServer CategoryHugo )
func (Category) String ¶
type ParseConfig ¶
type ParseConfig struct { Version int }
ParseConfig holds configuration extracted from the template.
type ParseInfo ¶
type ParseInfo struct { // Set for shortcode templates with any {{ .Inner }} IsInner bool // Set for partials with a return statement. HasReturn bool // Config extracted from template. Config ParseConfig }
ParseInfo holds information about a parsed ntemplate.
func (ParseInfo) IsZero ¶
type PathTemplateDescriptor ¶
type PathTemplateDescriptor struct { Path string Desc TemplateDescriptor }
type SiteOptions ¶
type StoreOptions ¶
type StoreOptions struct { // The filesystem to use. Fs afero.Fs // The logger to use. Log loggers.Logger // The path parser to use. PathParser *paths.PathParser // Set when --enableTemplateMetrics is set. Metrics metrics.Provider // All configured output formats. OutputFormats output.Formats // All configured media types. MediaTypes media.Types // The default content language. DefaultContentLanguage string // The default output format. DefaultOutputFormat string // Taxonomy config. TaxonomySingularPlural map[string]string // Whether we are in watch or server mode. Watching bool // contains filtered or unexported fields }
type SubCategory ¶
type SubCategory int
const ( SubCategoryMain SubCategory = iota SubCategoryEmbedded // Internal Hugo templates SubCategoryInline // Inline partials )
func (SubCategory) String ¶
func (i SubCategory) String() string
type TemplInfo ¶
type TemplInfo struct { // PathInfo info. PathInfo *paths.Path // Set when backed by a file. Fi hugofs.FileMetaInfo // The parsed template. // Note that any baseof template will be applied later. Template tpl.Template // The descriptior that this template represents. D TemplateDescriptor // Parser state. ParseInfo ParseInfo // contains filtered or unexported fields }
func (*TemplInfo) Base ¶
func (ti *TemplInfo) Base() tpl.CurrentTemplateInfoCommonOps
Implements the additional methods in tpl.CurrentTemplateInfoOps.
func (*TemplInfo) BaseVariantsSeq ¶
func (ti *TemplInfo) BaseVariantsSeq() iter.Seq[*TemplWithBaseApplied]
func (*TemplInfo) Filename ¶
func (*TemplInfo) GetIdentity ¶
func (*TemplInfo) IdentifierBase ¶
func (*TemplInfo) IsProbablyDependency ¶
func (*TemplInfo) IsProbablyDependent ¶
func (*TemplInfo) Name ¶
func (*TemplInfo) Prepare ¶
func (ti *TemplInfo) Prepare() (*texttemplate.Template, error)
func (*TemplInfo) String ¶
func (*TemplInfo) SubCategory ¶
func (ti *TemplInfo) SubCategory() SubCategory
type TemplWithBaseApplied ¶
type TemplWithBaseApplied struct { // The template that's overlaid on top of the base template. Overlay *TemplInfo // The base template. Base *TemplInfo // This is the final template that can be used to render a page. Template *TemplInfo }
type TemplateDescriptor ¶
type TemplateDescriptor struct { // Group 1. Kind string // page, home, section, taxonomy, term (and only those) LayoutFromTemplate string // list, single, all,mycustomlayout LayoutFromUser string // custom layout set in front matter, e.g. list, single, all, mycustomlayout // Group 2. OutputFormat string // rss, csv ... MediaType string // text/html, text/plain, ... Lang string // en, nn, fr, ... Variant1 string // contextual variant, e.g. "link" in render hooks." Variant2 string // contextual variant, e.g. "id" in render. // Misc. LayoutFromUserMustMatch bool // If set, we only look for the exact layout. IsPlainText bool // Whether this is a plain text template. }
This is used both as a key and in lookups.
func (TemplateDescriptor) IsZero ¶
func (d TemplateDescriptor) IsZero() bool
type TemplateQuery ¶
type TemplateQuery struct { // The path to walk down to. Path string // The name to look for. Used for shortcode queries. Name string // The category to look in. Category Category // The template descriptor to match against. Desc TemplateDescriptor // Whether to even consider this candidate. Consider func(candidate *TemplInfo) bool }
TemplateQuery is used in LookupPagesLayout to find the best matching template.
type TemplateStore ¶
type TemplateStore struct {
// contains filtered or unexported fields
}
func NewStore ¶
func NewStore(opts StoreOptions, siteOpts SiteOptions) (*TemplateStore, error)
func (*TemplateStore) ExecuteWithContext ¶
func (t *TemplateStore) ExecuteWithContext(ctx context.Context, ti *TemplInfo, wr io.Writer, data any) error
func (*TemplateStore) FindAllBaseTemplateCandidates ¶
func (s *TemplateStore) FindAllBaseTemplateCandidates(overlayKey string, desc TemplateDescriptor) []keyTemplateInfo
In the previous implementation of base templates in Hugo, we parsed and applied these base templates on request, e.g. in the middle of rendering. The idea was that we coulnd't know upfront which layoyt/base template combination that would be used. This, however, added a lot of complexity involving a careful dance of template cloning and parsing (Go HTML tenplates cannot be parsed after any of the templates in the tree have been executed). FindAllBaseTemplateCandidates finds all base template candidates for the given descriptor so we can apply them upfront. In this setup we may end up with unused base templates, but not having to do the cloning should more than make up for that.
func (*TemplateStore) GetFunc ¶
func (t *TemplateStore) GetFunc(name string) (reflect.Value, bool)
func (*TemplateStore) GetIdentity ¶
func (s *TemplateStore) GetIdentity(p string) identity.Identity
func (*TemplateStore) HasTemplate ¶
func (s *TemplateStore) HasTemplate(templatePath string) bool
func (*TemplateStore) LookupByPath ¶
func (t *TemplateStore) LookupByPath(templatePath string) *TemplInfo
func (*TemplateStore) LookupPagesLayout ¶
func (s *TemplateStore) LookupPagesLayout(q TemplateQuery) *TemplInfo
func (*TemplateStore) LookupPartial ¶
func (s *TemplateStore) LookupPartial(pth string) *TemplInfo
func (*TemplateStore) LookupShortcode ¶
func (s *TemplateStore) LookupShortcode(q TemplateQuery) *TemplInfo
func (*TemplateStore) NewFromOpts ¶
func (s *TemplateStore) NewFromOpts() (*TemplateStore, error)
NewFromOpts creates a new store with the same configuration as the original. Used for testing/benchmarking.
func (*TemplateStore) PrintDebug ¶
func (s *TemplateStore) PrintDebug(prefix string, category Category, w io.Writer)
PrintDebug is for testing/debugging only.
func (*TemplateStore) RefreshFiles ¶
func (s *TemplateStore) RefreshFiles(include func(fi hugofs.FileMetaInfo) bool) error
RefreshFiles refreshes this store for the files matching the given predicate.
func (*TemplateStore) TextLookup ¶
func (t *TemplateStore) TextLookup(name string) *TemplInfo
func (*TemplateStore) TextParse ¶
func (t *TemplateStore) TextParse(name, tpl string) (*TemplInfo, error)
func (*TemplateStore) UnusedTemplates ¶
func (t *TemplateStore) UnusedTemplates() []*TemplInfo
func (TemplateStore) WithSiteOpts ¶
func (s TemplateStore) WithSiteOpts(opts SiteOptions) *TemplateStore
WithSiteOpts creates a new store with the given site options. This is used to create per site template store, all sharing the same templates, but with a different template function execution context.
type TemplateStoreProvider ¶
type TemplateStoreProvider interface { GetTemplateStore() *TemplateStore }
type TextTemplatHandler ¶
type TextTemplatHandler interface { ExecuteWithContext(ctx context.Context, ti *TemplInfo, wr io.Writer, data any) error TextLookup(name string) *TemplInfo TextParse(name, tpl string) (*TemplInfo, error) }
Source Files ¶
category_string.go legacy.go subcategory_string.go template_funcs.go template_info.go templatedescriptor.go templates.go templatestore.go templatetransform.go
- Version
- v0.146.3
- Published
- Apr 12, 2025
- Platform
- linux/amd64
- Imports
- 44 packages
- Last checked
- 3 hours ago –
Tools for package owners.