nunjucks-embed

0.1.0 • Public • Published

nunjucks-embed

A Twig-like embed custom tag for Nunjucks.

Usage

yarn add nunjucks-embed
let EmbedTag = require('nunjucks-embed');
env.addExtension('EmbedTag', new EmbedTag({ /* options */ }));

my-template.njk

{% embed 'note.njk' %}
    {% block content %}
    Hello world!
    {% endblock %}
{% endembed %}

note.njk

<div class='note'>
    {% block content %}
    <!-- content here -->
    {% endblock %}
</div>

Results in:

<div class='note'>
    Hello world!
</div>

Context

By default, the embedded template will have access to the current context. To explicitly pass or ingore it, use with context and without context:

{% embed with context 'note.njk' %}
    ...
{% endembed %}

Options

  • sync: boolean, default true — whether to register it as a synchronous or asynchronous custom tag

Readme

Keywords

none

Package Sidebar

Install

npm i nunjucks-embed

Weekly Downloads

37

Version

0.1.0

License

MIT

Unpacked Size

5.41 kB

Total Files

22

Last publish

Collaborators

  • danburzo