Interface TwingEnvironment

interface TwingEnvironment {
    cache: null | TwingCache;
    charset: string;
    dateFormat: string;
    dateIntervalFormat: string;
    escapingStrategyHandlers: Record<string, TwingEscapingStrategyHandler>;
    filters: Map<string, TwingFilter>;
    functions: Map<string, TwingFunction>;
    globals: TwingContext<string, any>;
    loader: TwingLoader | TwingSynchronousLoader;
    numberFormat: TwingNumberFormat;
    sandboxPolicy: TwingSandboxSecurityPolicy;
    tests: Map<string, TwingTest>;
    timezone: string;
    addExtension(extension: TwingExtension): void;
    addFilter(filter: TwingFilter): void;
    addFunction(aFunction: TwingFunction): void;
    addNodeVisitor(visitor: TwingNodeVisitor): void;
    addOperator(operator: TwingOperator): void;
    addTagHandler(parser: TwingTagHandler): void;
    addTest(test: TwingTest): void;
    loadTemplate(name: string, from?: null | string): Promise<TwingTemplate>;
    parse(stream: TwingTokenStream, options?: TwingParserOptions): TwingTemplateNode;
    registerEscapingStrategy(handler: TwingEscapingStrategyHandler, name: string): void;
    render(name: string, context: Record<string, any>, options?: {
        sandboxed?: boolean;
        strict?: boolean;
    }): Promise<string>;
    renderWithSourceMap(name: string, context: Record<string, any>, options?: {
        sandboxed?: boolean;
        strict?: boolean;
    }): Promise<{
        data: string;
        sourceMap: RawSourceMap;
    }>;
    tokenize(source: TwingSource): TwingTokenStream;
}

Properties

cache: null | TwingCache
charset: string
dateFormat: string
dateIntervalFormat: string
escapingStrategyHandlers: Record<string, TwingEscapingStrategyHandler>
filters: Map<string, TwingFilter>
functions: Map<string, TwingFunction>
globals: TwingContext<string, any>
numberFormat: TwingNumberFormat
tests: Map<string, TwingTest>
timezone: string

Methods

  • Loads a template by its name.

    Parameters

    • name: string

      The name of the template to load

    • Optionalfrom: null | string

      The name of the template that requested the load

    Returns Promise<TwingTemplate>

    When the template cannot be found

    When an error occurred during the parsing of the source

  • Convenient method that renders a template from its name.

    Parameters

    • name: string
    • context: Record<string, any>
    • Optionaloptions: {
          sandboxed?: boolean;
          strict?: boolean;
      }
      • Optionalsandboxed?: boolean
      • Optionalstrict?: boolean

    Returns Promise<string>

  • Convenient method that renders a template from its name and returns both the render result and its belonging source map.

    Parameters

    • name: string
    • context: Record<string, any>
    • Optionaloptions: {
          sandboxed?: boolean;
          strict?: boolean;
      }
      • Optionalsandboxed?: boolean
      • Optionalstrict?: boolean

    Returns Promise<{
        data: string;
        sourceMap: RawSourceMap;
    }>