package tpl
import "github.com/gohugoio/hugo/tpl"
Package tpl contains template functions and related types.
Index ¶
- Constants
- Variables
- func StripHTML(s string) string
- type DeferredExecution
- type FileInfo
- type Info
- type IsInternalTemplateProvider
- type ParseConfig
- type ParseInfo
- type RenderingContext
- type Template
- type TemplateDebugger
- type TemplateExecutor
- type TemplateFinder
- type TemplateFuncGetter
- type TemplateHandler
- type TemplateHandlers
- type TemplateLookup
- type TemplateLookupVariant
- type TemplateManager
- type TemplateParseFinder
- type TemplateParser
- type TemplateVariants
- type TemplatesProvider
- type UnusedTemplatesProvider
Constants ¶
const ( HugoDeferredTemplatePrefix = "__hdeferred/" HugoDeferredTemplateSuffix = "__d=" )
const TemplateVersion = 2
Increments on breaking changes.
Variables ¶
var Context = struct { DependencyManagerScopedProvider hcontext.ContextDispatcher[identity.DependencyManagerScopedProvider] GetDependencyManagerInCurrentScope func(context.Context) identity.Manager DependencyScope hcontext.ContextDispatcher[int] Page hcontext.ContextDispatcher[page] IsInGoldmark hcontext.ContextDispatcher[bool] }{ DependencyManagerScopedProvider: hcontext.NewContextDispatcher[identity.DependencyManagerScopedProvider](contextKey("DependencyManagerScopedProvider")), DependencyScope: hcontext.NewContextDispatcher[int](contextKey("DependencyScope")), Page: hcontext.NewContextDispatcher[page](contextKey("Page")), IsInGoldmark: hcontext.NewContextDispatcher[bool](contextKey("IsInGoldmark")), }
Context manages values passed in the context to templates.
var DefaultParseConfig = ParseConfig{ Version: TemplateVersion, }
var DefaultParseInfo = ParseInfo{ Config: DefaultParseConfig, }
Functions ¶
func StripHTML ¶
StripHTML strips out all HTML tags in s.
Types ¶
type DeferredExecution ¶
type DeferredExecution struct { Mu sync.Mutex Ctx context.Context TemplateName string Data any Executed bool Result string }
type FileInfo ¶
type Info ¶
type Info interface { ParseInfo() ParseInfo }
type IsInternalTemplateProvider ¶
type IsInternalTemplateProvider interface { IsInternalTemplate() bool }
type ParseConfig ¶
type ParseConfig struct { Version int }
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 }
func (ParseInfo) IsZero ¶
type RenderingContext ¶
type RenderingContext struct { Site site SiteOutIdx int }
type Template ¶
type Template interface { Name() string Prepare() (*texttemplate.Template, error) }
Template is the common interface between text/template and html/template.
func AddIdentity ¶
AddIdentity checks if t is an identity.Identity and returns it if so. Else it wraps it in a templateIdentity using its name as the base.
type TemplateDebugger ¶
type TemplateDebugger interface {
Debug()
}
TemplateDebugger prints some debug info to stdout.
type TemplateExecutor ¶
type TemplateExecutor interface { ExecuteWithContext(ctx context.Context, t Template, wr io.Writer, data any) error }
type TemplateFinder ¶
type TemplateFinder interface { TemplateLookup TemplateLookupVariant }
TemplateFinder finds templates.
type TemplateFuncGetter ¶
TemplateFuncGetter allows to find a template func by name.
type TemplateHandler ¶
type TemplateHandler interface { TemplateFinder TemplateExecutor LookupLayout(d layouts.LayoutDescriptor, f output.Format) (Template, bool, error) HasTemplate(name string) bool GetIdentity(name string) (identity.Identity, bool) }
TemplateHandler finds and executes templates.
type TemplateHandlers ¶
type TemplateHandlers struct { Tmpl TemplateHandler TxtTmpl TemplateParseFinder }
TemplateHandlers holds the templates needed by Hugo.
type TemplateLookup ¶
type TemplateLookupVariant ¶
type TemplateLookupVariant interface { // TODO(bep) this currently only works for shortcodes. // We may unify and expand this variant pattern to the // other templates, but we need this now for the shortcodes to // quickly determine if a shortcode has a template for a given // output format. // It returns the template, if it was found or not and if there are // alternative representations (output format, language). // We are currently only interested in output formats, so we should improve // this for speed. LookupVariant(name string, variants TemplateVariants) (Template, bool, bool) LookupVariants(name string) []Template }
type TemplateManager ¶
type TemplateManager interface { TemplateHandler TemplateFuncGetter AddTemplate(name, tpl string) error }
TemplateManager manages the collection of templates.
type TemplateParseFinder ¶
type TemplateParseFinder interface { TemplateParser TemplateFinder }
TemplateParseFinder provides both parsing and finding.
type TemplateParser ¶
TemplateParser is used to parse ad-hoc templates, e.g. in the Resource chain.
type TemplateVariants ¶
TemplateVariants describes the possible variants of a template. All of these may be empty.
type TemplatesProvider ¶
type TemplatesProvider interface { Tmpl() TemplateHandler TextTmpl() TemplateParseFinder }
TemplatesProvider as implemented by deps.Deps.
type UnusedTemplatesProvider ¶
type UnusedTemplatesProvider interface { UnusedTemplates() []FileInfo }
UnusedTemplatesProvider lists unused templates if the build is configured to track those.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
tpl/cast | Package cast provides template functions for data type conversions. |
tpl/collections | Package collections provides template functions for manipulating collections such as arrays, maps, and slices. |
tpl/compare | Package compare provides template functions for comparing values. |
tpl/crypto | Package crypto provides template functions for cryptographic operations. |
tpl/css | |
tpl/data | Package data provides template functions for working with external data sources. |
tpl/debug | Package debug provides template functions to help debugging templates. |
tpl/diagrams | Package diagrams provides template functions for generating diagrams. |
tpl/encoding | Package encoding provides template functions for encoding content. |
tpl/fmt | Package fmt provides template functions for formatting strings. |
tpl/hash | Package hash provides non-cryptographic hash functions for template use. |
tpl/hugo | Package hugo provides template functions for accessing the Site Hugo object. |
tpl/images | Package images provides template functions for manipulating images. |
tpl/inflect | Package inflect provides template functions for the inflection of words. |
tpl/internal | |
tpl/js | Package js provides functions for building JavaScript resources |
tpl/lang | Package lang provides template functions for content internationalization. |
tpl/math | Package math provides template functions for mathematical operations. |
tpl/openapi | Package openapi provides functions for generating OpenAPI (Swagger) documentation. |
tpl/openapi/openapi3 | Package openapi3 provides functions for generating OpenAPI v3 (Swagger) documentation. |
tpl/os | Package os provides template functions for interacting with the operating system. |
tpl/page | Package page provides template functions for accessing the current Page object, the entry level context for the current template. |
tpl/partials | Package partials provides template functions for working with reusable templates. |
tpl/path | Package path provides template functions for manipulating paths. |
tpl/reflect | Package reflect provides template functions for run-time object reflection. |
tpl/resources | Package resources provides template functions for working with resources. |
tpl/safe | Package safe provides template functions for escaping untrusted content or encapsulating trusted content. |
tpl/site | Package site provides template functions for accessing the Site object. |
tpl/strings | Package strings provides template functions for manipulating strings. |
tpl/templates | Package templates provides template functions for working with templates. |
tpl/time | Package time provides template functions for measuring and displaying time. |
tpl/tplimpl | |
tpl/transform | Package transform provides template functions for transforming content. |
tpl/urls | Package urls provides template functions to deal with URLs. |
- Version
- v0.144.2 (latest)
- Published
- Feb 19, 2025
- Platform
- linux/amd64
- Imports
- 15 packages
- Last checked
- 34 minutes ago –
Tools for package owners.