Member Junction
    Preparing search index...

    TemplateEngine is used for accessing template metadata/caching it, and rendering templates

    Hierarchy (View Summary)

    Index

    Constructors

    Accessors

    • get GlobalKey(): string

      Returns string

    Methods

    • Loads the single TemplateEngineBase metadata cache, then (re)initializes the render layer. The base runs its own AdditionalLoading (associating content/params with each template) inside its Config(); afterwards we drop any stale compiled templates and one-time-initialize the nunjucks environment.

      NOTE: when this extended the base, the nunjucks setup lived in an AdditionalLoading() override that the base's Load() invoked. Under composition the base's Load() calls the BASE's AdditionalLoading, not ours, so we drive the render-layer init explicitly here after the cache is loaded.

      Parameters

      Returns Promise<void>

    • Simple utility method to create a new Nunjucks template object and bind it to a Nunjucks environment.

      Parameters

      • templateText: string
      • env: Environment = ...

        the environment to bind to; defaults to the shared autoescape environment

      Returns any

    • The Global Object Store is a place to store global objects that need to be shared across the application. Depending on the execution environment, this could be the window object in a browser, or the global object in a node environment, or something else in other contexts. The key here is that in some cases static variables are not truly shared because it is possible that a given class might have copies of its code in multiple paths in a deployed application. This approach ensures that no matter how many code copies might exist, there is only one instance of the object in question by using the Global Object Store.

      Returns GlobalObjectStore

    • This method is responsible for creating a new Nunjucks template, caching it, and returning it. If the templateContentId already had a template created, it will return that template from the cache.

      Parameters

      • templateContentId: string
      • templateText: string
      • cacheTemplate: boolean

        if true, the template will be cached, otherwise it will not be cached

      Returns any

    • Merges default values from template parameters with the provided data. Content-specific parameters take precedence over global parameters when both define the same parameter name.

      Parameters

      • templateEntity: MJTemplateEntityExtended

        The template entity containing parameter definitions

      • contentId: string

        The ID of the template content being rendered

      • data: any

        The input data provided by the caller

      Returns any

      A new object containing merged data with defaults applied

      • Only applies defaults for parameters that are not already present in the input data
      • Handles all parameter types: Scalar, Array, Object, Record, Entity
      • Content-specific parameter defaults override global parameter defaults
    • Promisifies the Nunjucks template rendering process.

      Parameters

      • template: Template

        the Nunjucks template object

      • data: any

        the data to render the template with

      Returns Promise<string>

    • Simple rendering utilty method. Use this to render any valid Nunjucks Template within the Nunjucks environment created by the Template Engine without having to use the stored metadata (Templates/Template Contents/Template Params/etc) within the MJ database. This is useful when you have a template that is stored elsewhere or dynamically created and you just want to render it with some data.

      Parameters

      • templateText: string
      • data: any
      • Optionaloptions: { autoescape?: boolean }

        optional render controls. autoescape (default true) toggles HTML-entity escaping — pass false for plain-text contexts such as email subject lines, where Acme & Co must not become Acme &amp; Co.

      Returns Promise<TemplateRenderResult>

    • Returns the singleton instance of the class. If the instance does not exist, it is created and stored in the Global Object Store. If className is provided it will be used as part of the key in the Global Object Store, otherwise the actual class name will be used. NOTE: the class name used by default is the lowest level of the object hierarchy, so if you have a class that extends another class, the lowest level class name will be used.

      Type Parameters

      Parameters

      • this: new () => T
      • OptionalclassName: string

      Returns T