Skip to main content

Class: RenderContext

Defined in: src/context.ts:74

Render-time state. A new render context is created automatically for every call to Template.render() or Template.renderSync().

Constructors​

Constructor​

new RenderContext(template, options?): RenderContext

Defined in: src/context.ts:158

Parameters​

template​

Template

options?​

RenderContextOptions

Returns​

RenderContext

Properties​

assignScore​

assignScore: number = 0

Defined in: src/context.ts:78

A non-specific indicator of template local scope usage.


assignScoreCumulative​

assignScoreCumulative: number

Defined in: src/context.ts:84

A non-specific indicator of template local scope usage for the current template and all partial templates combined.


disabledTags​

readonly disabledTags: Set<string> | undefined

Defined in: src/context.ts:99

Names of tags that are disallowed in this context.


env​

readonly env: Environment

Defined in: src/context.ts:105

The Liquid environment this render context and associated template is bound to.


forloops​

readonly forloops: ForLoop[] = []

Defined in: src/context.ts:110

A stack of ForLoop drops used to populate forloop.parent.


interrupts​

readonly interrupts: symbol[] = []

Defined in: src/context.ts:122

A stack of interrupt signals used by {% break %} and {% continue %}, for example.


registers​

readonly registers: Map<string | symbol, unknown>

Defined in: src/context.ts:134

Registers supporting stateful tags. It's OK to use this map for storing custom tag state.


renderScore​

renderScore: number = 0

Defined in: src/context.ts:139

The number of nodes rendered for the current template.


renderScoreCumulative​

renderScoreCumulative: number

Defined in: src/context.ts:145

The number of nodes rendered for the current template and all partial templates.


template​

template: Template

Defined in: src/context.ts:156

The current template being rendered.

Methods​

assign()​

assign(name, value): void

Defined in: src/context.ts:186

Set name to value in the template local scope.

Parameters​

name​

string

value​

unknown

Returns​

void


copy()​

copy(namespace, options?): RenderContext

Defined in: src/context.ts:210

Return a new render context with render state from this context.

The caller is responsible for updating renderScoreCumulative when the new context is no longer needed.

Parameters​

namespace​

Record<string, unknown>

options?​

ContextCopyOptions = {}

Returns​

RenderContext


decrement()​

decrement(name): number

Defined in: src/context.ts:240

Parameters​

name​

string

Returns​

number


extend()​

extend(namespace, callback, template?): Promise<void>

Defined in: src/context.ts:265

Temporarily extend this render context with variables from namespace.

Push namespace to the front of the scope stack for the duration of callback.

If template is given, sets the current template for the duration of callback, before restoring the previous template.

This is used by the built-in {% include %} tag, where parent and partial templates share render context state, with additional partial-scoped variables.

Parameters​

namespace​

Record<string, unknown>

callback​

() => Promise<void>

template?​

Template

Returns​

Promise<void>


extendSync()​

extendSync(namespace, callback, template?): void

Defined in: src/context.ts:308

Temporarily extend this render context with variables from namespace.

Push namespace to the front of the scope stack for the duration of callback.

If template is given, sets the current template for the duration of callback, before restoring the previous template.

This is used by the built-in {% include %} tag, where parent and partial templates share render context state, with additional partial-scoped variables.

Parameters​

namespace​

Record<string, unknown>

callback​

() => void

template?​

Template

Returns​

void


getRegister()​

getRegister<V>(key, defaultFactory): V

Defined in: src/context.ts:342

Return a register for key. If a register does not yet exist for key, add and return the result of calling defaultFactory.

Type Parameters​

V​

V

Parameters​

key​

string | symbol

defaultFactory​

() => V

Returns​

V


increment()​

increment(name): number

Defined in: src/context.ts:350

Parameters​

name​

string

Returns​

number


resolve()​

resolve(name): unknown

Defined in: src/context.ts:365

Lookup name in the current scope. Return the special Nothing value if name is not defined.

Parameters​

name​

string

Returns​

unknown


resolvePath()​

resolvePath(obj, segments): Promise<[unknown, number]>

Defined in: src/context.ts:374

Follow path segments starting at obj. If the path from obj does not exist, the special Nothing value is returned along with the index of the last segment to be successfully resolved.

Parameters​

obj​

unknown

segments​

unknown[]

Returns​

Promise<[unknown, number]>


resolvePathSync()​

resolvePathSync(obj, segments): [unknown, number]

Defined in: src/context.ts:437

A sync version of resolvePath. The only difference is the handling of the async Drop protocol.

Parameters​

obj​

unknown

segments​

unknown[]

Returns​

[unknown, number]


toArray()​

toArray(expression): Promise<unknown[]>

Defined in: src/context.ts:504

Evaluate expression and coerce the result to an array.

Parameters​

expression​

Expression | undefined

Returns​

Promise<unknown[]>


toArraySync()​

toArraySync(expression): unknown[]

Defined in: src/context.ts:513

Evaluate expression and coerce the result to an array.

Parameters​

expression​

Expression | undefined

Returns​

unknown[]


toInteger()​

toInteger<T>(expression, default_): Promise<number | T>

Defined in: src/context.ts:522

Evaluate expression and coerce the result to an integer.

Type Parameters​

T​

T

Parameters​

expression​

Expression | undefined

default_​

T

Returns​

Promise<number | T>


toIntegerSync()​

toIntegerSync<T>(expression, default_): number | T

Defined in: src/context.ts:538

Evaluate expression and coerce the result to an integer.

Type Parameters​

T​

T

Parameters​

expression​

Expression | undefined

default_​

T

Returns​

number | T