Class: Template
A Liquid template that has been parsed and is bound to an environment,
ready to be rendered. Rather than constructing a template directly, you
should use Template.fromString(), Environment.fromString() or
Environment.getTemplate().
Constructors
new Template()
new Template(
environment,tree,globals?,templateContext?):Template
Template constructor. Rather than constructing a template directly, you
should use Template.fromString(), Environment.fromString() or
Environment.getTemplate().
Parameters
• environment: Environment
The environment this template is bound to.
• tree: Root
The root of the abstract syntax tree representing this template.
• globals?: ContextScope
An optional object who's properties will be added to the render context every time the resulting template is rendered.
• templateContext?: TemplateContext = {}
Optional meta data. Mostly for managing loading and reloading of templates.
Returns
Defined in
Properties
environment
readonlyenvironment:Environment
Defined in
globals
readonlyglobals:ContextScope
Defined in
isUpToDate()
readonlyisUpToDate: () =>Promise<boolean>
Returns
Promise<boolean>
Defined in
isUpToDateSync()
readonlyisUpToDateSync: () =>boolean
Returns
boolean
Defined in
loaderContext
readonlyloaderContext:ContextScope
Defined in
matter
readonlymatter:ContextScope
Defined in
name
readonlyname:string
Defined in
renderContextClass
protectedrenderContextClass: typeofRenderContext=RenderContext
Defined in
tree
readonlytree:Root
Defined in
Methods
analyze()
analyze(
options):Promise<TemplateAnalysis>
Statically analyze this template and any included/rendered templates. Currently we only analyze references to template variables.
Parameters
• options: TemplateAnalysisOptions = {}
Template analysis options.
Returns
Promise<TemplateAnalysis>
Defined in
analyzeSync()
analyzeSync(
options):TemplateAnalysis
A synchronous version of analyze
Parameters
• options: TemplateAnalysisOptions = {}
Template analysis options.
Returns
See
Defined in
handleError()
protectedhandleError(error,node,blockScope,partial):void
Parameters
• error: unknown
• node: Node
• blockScope: boolean
• partial: boolean
Returns
void
Defined in
makeGlobals()
protectedmakeGlobals(templateGlobals):ContextScope
Combine render context global variables from the bound environment,
the "matter" object originating from a template loader (if any) and
those passed to render().
Override this to change global template scope priorities.
Parameters
• templateGlobals: ContextScope
Returns
Defined in
render()
render(
globals):Promise<string>
Render the template.
Parameters
• globals: ContextScope = {}
An optional object who's properties will be added to the render context,
Returns
Promise<string>
The rendered template.
Defined in
renderSync()
renderSync(
globals):string
A synchronous version of render.
Parameters
• globals: ContextScope = {}
Returns
string
See
Defined in
renderWithContext()
renderWithContext(
context,outputStream,blockScope,partial):Promise<void>
Render a template given an existing render context and output stream.
This is used by the built-in include and render tags.
Parameters
• context: RenderContext
• outputStream: RenderStream
• blockScope: boolean = false
• partial: boolean = false
Returns
Promise<void>
Defined in
renderWithContextSync()
renderWithContextSync(
context,outputStream,blockScope,partial):void
A synchronous version of renderWithContext.
Parameters
• context: RenderContext
• outputStream: RenderStream
• blockScope: boolean = false
• partial: boolean = false
Returns
void
See
Defined in
withGlobals()
withGlobals(
globals?):Template
Copy this template with new render context globals.
Parameters
• globals?: ContextScope
An object who's properties will be added to the render context every time this template is rendered.
Returns
A copy of this template with new render context globals.
Defined in
from()
staticfrom(source,templateGlobals?,options?):Template
Parse a Liquid template, automatically creating an environment to bind it to.
Alias of fromString
Parameters
• source: string
The Liquid template source code.
• templateGlobals?: ContextScope
Global render context variables that will included every time this template is rendered.
• options?: EnvironmentOptions = {}
Options to set on the implicit environment.
Returns
A new template, bound to an implicit environment.
Defined in
fromString()
staticfromString(source,templateGlobals?,options?):Template
Parse a Liquid template, automatically creating an environment to bind it to.
Parameters
• source: string
The Liquid template source code.
• templateGlobals?: ContextScope
Global render context variables that will included every time this template is rendered.
• options?: EnvironmentOptions = {}
Options to set on the implicit environment. globals
and loader will be ignored when creating an implicit environment.
Returns
A new template, bound to an implicit environment.