package tpl

import ""


Package Files

template.go template_info.go


const TemplateVersion = 2

Increments on breaking changes.


var DefaultParseConfig = ParseConfig{
    Version: TemplateVersion,
var DefaultParseInfo = ParseInfo{
    Config: DefaultParseConfig,

func GetDataFromContext

func GetDataFromContext(ctx context.Context) any

GetDataFromContext returns the template data context (usually .Page) from ctx if set. NOte: This is not fully implemented yet.

func GetHasLockFromContext

func GetHasLockFromContext(ctx context.Context) bool

func SetHasLockInContext

func SetHasLockInContext(ctx context.Context, hasLock bool) context.Context

type FileInfo

type FileInfo interface {
    Name() string
    Filename() string

type Info

type Info interface {
    ParseInfo() ParseInfo

    // Identifies this template and its dependencies.

func NewInfo

func NewInfo(id identity.Manager, parseInfo ParseInfo) Info

type InfoManager

type InfoManager interface {
    ParseInfo() ParseInfo

    // Identifies and manages this template and its dependencies.

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

func (info ParseInfo) IsZero() bool

type Template

type Template interface {
    Name() string
    Prepare() (*texttemplate.Template, error)

Template is the common interface between text/template and html/template.

func WithInfo

func WithInfo(templ Template, info Info) Template

WithInfo wraps the info in a template.

type TemplateDebugger

type TemplateDebugger interface {

TemplateDebugger prints some debug info to stdout.

type TemplateFinder

type TemplateFinder interface {

TemplateFinder finds templates.

type TemplateFuncGetter

type TemplateFuncGetter interface {
    GetFunc(name string) (reflect.Value, bool)

TemplateFuncGetter allows to find a template func by name.

type TemplateHandler

type TemplateHandler interface {
    Execute(t Template, wr io.Writer, data any) error
    ExecuteWithContext(ctx context.Context, t Template, wr io.Writer, data any) error
    LookupLayout(d output.LayoutDescriptor, f output.Format) (Template, bool, error)
    HasTemplate(name string) bool

TemplateHandler finds and executes templates.

type TemplateLookup

type TemplateLookup interface {
    Lookup(name string) (Template, bool)

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 {
    AddTemplate(name, tpl string) error
    MarkReady() error

TemplateManager manages the collection of templates.

type TemplateParseFinder

type TemplateParseFinder interface {

TemplateParseFinder provides both parsing and finding.

type TemplateParser

type TemplateParser interface {
    Parse(name, tpl string) (Template, error)

TemplateParser is used to parse ad-hoc templates, e.g. in the Resource chain.

type TemplateVariants

type TemplateVariants struct {
    Language     string
    OutputFormat output.Format

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.


tpl/castPackage cast provides template functions for data type conversions.
tpl/collectionsPackage collections provides template functions for manipulating collections such as arrays, maps, and slices.
tpl/comparePackage compare provides template functions for comparing values.
tpl/cryptoPackage crypto provides template functions for cryptographic operations.
tpl/dataPackage data provides template functions for working with external data sources.
tpl/debugPackage debug provides template functions to help debugging templates.
tpl/encodingPackage encoding provides template functions for encoding content.
tpl/fmtPackage fmt provides template functions for formatting strings.
tpl/hugoPackage hugo provides template functions for accessing the Site Hugo object.
tpl/imagesPackage images provides template functions for manipulating images.
tpl/inflectPackage inflect provides template functions for the inflection of words.
tpl/jsPackage js provides functions for building JavaScript resources
tpl/langPackage lang provides template functions for content internationalization.
tpl/mathPackage math provides template functions for mathematical operations.
tpl/osPackage os provides template functions for interacting with the operating system.
tpl/partialsPackage partials provides template functions for working with reusable templates.
tpl/pathPackage path provides template functions for manipulating paths.
tpl/reflectPackage reflect provides template functions for run-time object reflection.
tpl/resourcesPackage resources provides template functions for working with resources.
tpl/safePackage safe provides template functions for escaping untrusted content or encapsulating trusted content.
tpl/sitePackage site provides template functions for accessing the Site object.
tpl/stringsPackage strings provides template functions for manipulating strings.
tpl/templatesPackage templates provides template functions for working with templates.
tpl/timePackage time provides template functions for measuring and displaying time.
tpl/transformPackage transform provides template functions for transforming content.
tpl/urlsPackage urls provides template functions to deal with URLs.
v0.99.1 (latest)
May 18, 2022
7 packages (graph)
Last checked
1 hour ago

Tools for package owners.