Skip to main content

Class: Environment

Shared configuration from which templates can be loaded and parsed.

See

EnvironmentOptions

Constructors

new Environment()

new Environment(options): Environment

Environment constructor.

Parameters

options: EnvironmentOptions = {}

Environment options.

Returns

Environment

Defined in

src/environment.ts:211

Properties

autoEscape

autoEscape: boolean

Defined in

src/environment.ts:176


filters

readonly filters: object = {}

An object mapping filter names to filter functions.

Index Signature

[keys: string]: Filter

Defined in

src/environment.ts:195


globals

globals: ContextScope

Defined in

src/environment.ts:177


loader

loader: Loader

Defined in

src/environment.ts:178


localNamespaceLimit

localNamespaceLimit: number

Defined in

src/environment.ts:180


loopIterationLimit

loopIterationLimit: number

Defined in

src/environment.ts:181


maxContextDepth

maxContextDepth: number

Defined in

src/environment.ts:179


renderStreamFactory()

renderStreamFactory: (stream?) => RenderStream

Parameters

stream?: RenderStream

Returns

RenderStream

Defined in

src/environment.ts:190


statementEndString

readonly statementEndString: string

Defined in

src/environment.ts:184


statementStartString

readonly statementStartString: string

Defined in

src/environment.ts:183


strictFilters

strictFilters: boolean

Defined in

src/environment.ts:185


tagEndString

readonly tagEndString: string

Defined in

src/environment.ts:187


tagStartString

readonly tagStartString: string

Defined in

src/environment.ts:186


tags

readonly tags: object = {}

An object mapping tag names to tag implementations.

Index Signature

[keys: string]: Tag

Defined in

src/environment.ts:200


templateClass

protected templateClass: typeof Template = Template

Defined in

src/environment.ts:188


undefinedFactory()

readonly undefinedFactory: (name) => Undefined

Parameters

name: string

Returns

Undefined

Defined in

src/environment.ts:189

Accessors

outputStreamLimit

get outputStreamLimit(): number

set outputStreamLimit(value): void

Parameters

value: number

Returns

number

Defined in

src/environment.ts:392


parser

get parser(): Parser

Returns

Parser

Defined in

src/environment.ts:372

Methods

addFilter()

addFilter(name, filter): void

Add a filter to this environment.

Parameters

name: string

The filter's name, as used by template authors to apply the filter.

filter: Filter

A function implementing the filter.

Returns

void

Defined in

src/environment.ts:348


addTag()

addTag(name, tag): void

Add a tag to this environment.

Parameters

name: string

The tag's name, as used by template authors to use the tag.

tag: Tag

An object implementing the Tag interface.

Returns

void

Defined in

src/environment.ts:359


error()

error(err): void

Re-throw an error.

Override this method if you want to implement a "lax mode".

Parameters

err: Error

Returns

void

Defined in

src/environment.ts:368


fromString()

fromString(source, globals?, templateContext?): Template

Parse the given string as a Liquid template.

Parameters

source: string

The Liquid template source code.

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

Template

A Template bound to this environment, ready to be rendered.

Throws

NoSuchTemplateError if a template with the given name can not be found.

Defined in

src/environment.ts:328


getTemplate()

getTemplate(name, globals?, context?, loaderContext?): Promise<Template>

Load a template using the configured template loader.

Parameters

name: string

The name or identifier of the template to load.

globals?: ContextScope

An optional object who's properties will be added to the render context every time the resulting template is rendered.

context?: RenderContext

A reference to the active render context, if one is active.

loaderContext?

Additional, arbitrary data that a loader can use to scope or otherwise narrow its search space.

Returns

Promise<Template>

A Template bound to this environment, ready to be rendered.

Throws

NoSuchTemplateError if a template with the given name can not be found.

Defined in

src/environment.ts:295


getTemplateSync()

getTemplateSync(name, globals?, context?, loaderContext?): Template

A synchronous version of Environment.getTemplate().

Parameters

name: string

globals?: ContextScope

context?: RenderContext

loaderContext?

Returns

Template

See

getTemplate

Defined in

src/environment.ts:308


makeGlobals()

protected makeGlobals(templateGlobals?): ContextScope

Parameters

templateGlobals?: ContextScope

Returns

ContextScope

Defined in

src/environment.ts:387


parse()

protected parse(source, name?): Root

Parameters

source: string

name?: string

Returns

Root

Defined in

src/environment.ts:376


getImplicitEnvironment()

static getImplicitEnvironment(options): Environment

Return an environment configured with the given options. The globals and loader options are ignored when creating implicit environments.

Parameters

options: EnvironmentOptions = {}

Options for the implicit environment.

Returns

Environment

Defined in

src/environment.ts:270