Extension that enables recursive template embedding using {% template "TemplateName" %} syntax.

Features:

  • Recursive template inclusion with cycle detection
  • Content type inheritance with intelligent fallbacks
  • Data context passing and merging
  • Error handling for missing templates

Usage: {% template "TemplateName" %} {% template "TemplateName", type="HTML" %} {% template "TemplateName", data={extra: "value"} %} {% template "TemplateName", type="PlainText", data={key: "value"} %}

Hierarchy (view full)

Constructors

Properties

tags: string[] = []

One or more tags that represent case-sensitive tag names that will invoke this extension.

Accessors

Methods

  • Executes the template embedding logic with recursive template inclusion.

    Parameter Mapping from CallExtensionAsync:

    • In parse(): new nodes.CallExtensionAsync(this, 'run', params)
    • Results in: run(context, body, callBack)

    The body parameter will be undefined since TemplateEmbed is a self-closing tag that doesn't parse body content. The template name and configuration come from the parsed parameters instead.

    Parameters

    • context: any

      Nunjucks template rendering context containing variables and data

    • body: any

      Will be undefined for self-closing template tags (not used)

    • callBack: NunjucksCallback

      Async callback function to return results or errors

    Returns void

    Example

    {% template "HeaderTemplate" %}
    {% template "UserCard", type="HTML" %}
    {% template "Footer", data={year: 2024} %}