package tpl

import "github.com/gohugoio/hugo/tpl"

Package tpl contains template functions and related types.

Index

Constants

const (
	// HugoDeferredTemplatePrefix is the prefix for placeholders for deferred templates.
	HugoDeferredTemplatePrefix = "__hdeferred/"
	// HugoDeferredTemplateSuffix is the suffix for placeholders for deferred templates.
	HugoDeferredTemplateSuffix = "__d="
)

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]
	CurrentTemplate                    hcontext.ContextDispatcher[*CurrentTemplateInfo]
}{
	DependencyManagerScopedProvider: hcontext.NewContextDispatcher[identity.DependencyManagerScopedProvider](contextKeyDependencyManagerScopedProvider),
	DependencyScope:                 hcontext.NewContextDispatcher[int](contextKeyDependencyScope),
	Page:                            hcontext.NewContextDispatcher[page](contextKeyPage),
	IsInGoldmark:                    hcontext.NewContextDispatcher[bool](contextKeyIsInGoldmark),
	CurrentTemplate:                 hcontext.NewContextDispatcher[*CurrentTemplateInfo](cntextKeyCurrentTemplateInfo),
}

Context manages values passed in the context to templates.

Functions

func StripHTML

func StripHTML(s string) string

StripHTML strips out all HTML tags in s.

Types

type CurrentTemplateInfo

type CurrentTemplateInfo struct {
	Parent *CurrentTemplateInfo
	CurrentTemplateInfoOps
}

CurrentTemplateInfo as returned in templates.Current.

func (*CurrentTemplateInfo) Ancestors

func (ti *CurrentTemplateInfo) Ancestors() CurrentTemplateInfos

Ancestors returns the ancestors of the current template.

type CurrentTemplateInfoCommonOps

type CurrentTemplateInfoCommonOps interface {
	// Template name.
	Name() string
	// Template source filename.
	// Will be empty for internal templates.
	Filename() string
}

type CurrentTemplateInfoOps

type CurrentTemplateInfoOps interface {
	CurrentTemplateInfoCommonOps
	Base() CurrentTemplateInfoCommonOps
}

type CurrentTemplateInfos

type CurrentTemplateInfos []*CurrentTemplateInfo

CurrentTemplateInfos is a slice of CurrentTemplateInfo.

func (CurrentTemplateInfos) Reverse

Reverse creates a copy of the slice and reverses it.

type DeferredExecution

type DeferredExecution struct {
	Mu           sync.Mutex
	Ctx          context.Context
	TemplatePath string
	Data         any

	Executed bool
	Result   string
}

DeferredExecution holds the template and data for a deferred execution.

type RenderingContext

type RenderingContext struct {
	Site       site
	SiteOutIdx int
}

RenderingContext represents the currently rendered site/language.

type Template

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

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

Source Files

template.go

Directories

PathSynopsis
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/css
tpl/dataPackage data provides template functions for working with external data sources.
tpl/debugPackage debug provides template functions to help debugging templates.
tpl/diagramsPackage diagrams provides template functions for generating diagrams.
tpl/encodingPackage encoding provides template functions for encoding content.
tpl/fmtPackage fmt provides template functions for formatting strings.
tpl/hashPackage hash provides non-cryptographic hash functions for template use.
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/internal
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/openapiPackage openapi provides functions for generating OpenAPI (Swagger) documentation.
tpl/openapi/openapi3Package openapi3 provides functions for generating OpenAPI v3 (Swagger) documentation.
tpl/osPackage os provides template functions for interacting with the operating system.
tpl/pagePackage page provides template functions for accessing the current Page object, the entry level context for the current template.
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/tplimpl
tpl/tplimplinit
tpl/transformPackage transform provides template functions for transforming content.
tpl/urlsPackage urls provides template functions to deal with URLs.
Version
v0.146.2
Published
Apr 11, 2025
Platform
linux/amd64
Imports
11 packages
Last checked
1 second ago

Tools for package owners.