Interface TwingTemplate

The shape of a template. A template

interface TwingTemplate {
    aliases: TwingTemplateAliases;
    ast: TwingTemplateNode;
    blockHandlers: Map<string, TwingTemplateBlockHandler>;
    canBeUsedAsATrait: boolean;
    embeddedTemplates: Map<number, TwingTemplate>;
    macroHandlers: Map<string, TwingTemplateMacroHandler>;
    name: string;
    source: TwingSource;
    displayBlock(executionContext: TwingExecutionContext, name: string, useBlocks: boolean): Promise<void>;
    displayParentBlock(executionContext: TwingExecutionContext, name: string): Promise<void>;
    execute(environment: TwingEnvironment, context: TwingContext<any, any>, blocks: TwingTemplateBlockMap, outputBuffer: TwingOutputBuffer, options?: {
        nodeExecutor?: TwingNodeExecutor;
        sandboxed?: boolean;
        sourceMapRuntime?: TwingSourceMapRuntime;
        strict?: boolean;
        templateLoader?: TwingTemplateLoader;
    }): Promise<void>;
    getBlocks(executionContext: TwingExecutionContext): Promise<TwingTemplateBlockMap>;
    getParent(executionContext: TwingExecutionContext): Promise<null | TwingTemplate>;
    getTraits(executionContext: TwingExecutionContext): Promise<TwingTemplateBlockMap>;
    hasBlock(executionContext: TwingExecutionContext, name: string, blocks: TwingTemplateBlockMap): Promise<boolean>;
    hasMacro(name: string): Promise<boolean>;
    loadTemplate(executionContext: TwingExecutionContext, identifier: string | TwingTemplate | (null | string | TwingTemplate)[]): Promise<TwingTemplate>;
    render(environment: TwingEnvironment, context: Record<string, any>, options?: {
        nodeExecutor?: TwingNodeExecutor;
        outputBuffer?: TwingOutputBuffer;
        sandboxed?: boolean;
        sourceMapRuntime?: TwingSourceMapRuntime;
        strict?: boolean;
        templateLoader?: TwingTemplateLoader;
    }): Promise<string>;
}

Properties

blockHandlers: Map<string, TwingTemplateBlockHandler>
canBeUsedAsATrait: boolean
embeddedTemplates: Map<number, TwingTemplate>
macroHandlers: Map<string, TwingTemplateMacroHandler>
name: string
source: TwingSource

Methods

  • Semantically speaking, provide a closure to the template:

    • an environment providing the filters, functions, globals and tests;
    • a context providing the variables;
    • a block map providing the available blocks;
    • an output buffer providing the mean to output the result of an expression.

    Technically speaking, execute the template and stream the result to the output buffer.

    Parameters

    Returns Promise<void>