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
readonly
environment:Environment
Defined in
globals
readonly
globals:ContextScope
Defined in
isUpToDate()
readonly
isUpToDate: () =>Promise
<boolean
>
Returns
Promise
<boolean
>
Defined in
isUpToDateSync()
readonly
isUpToDateSync: () =>boolean
Returns
boolean
Defined in
loaderContext
readonly
loaderContext:ContextScope
Defined in
matter
readonly
matter:ContextScope
Defined in
name
readonly
name:string
Defined in
renderContextClass
protected
renderContextClass: typeofRenderContext
=RenderContext
Defined in
tree
readonly
tree: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()
protected
handleError(error
,node
,blockScope
,partial
):void
Parameters
• error: unknown
• node: Node
• blockScope: boolean
• partial: boolean
Returns
void
Defined in
makeGlobals()
protected
makeGlobals(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()
static
from(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()
static
fromString(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.