Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/marceljs/nunjucks-embed

A Twig-like `embed` custom tag for Nunjucks
https://github.com/marceljs/nunjucks-embed

nunjucks nunjucks-custom-tag twig

Last synced: 8 days ago
JSON representation

A Twig-like `embed` custom tag for Nunjucks

Awesome Lists containing this project

README

        

# nunjucks-embed

A [Twig-like `embed`](https://twig.symfony.com/doc/2.x/tags/embed.html) custom tag for Nunjucks.

## Usage

```bash
yarn add nunjucks-embed
```

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

__my-template.njk__
```njk
{% embed 'note.njk' %}
{% block content %}
Hello world!
{% endblock %}
{% endembed %}
```

__note.njk__
```njk


{% block content %}

{% endblock %}

```

Results in:

```html


Hello world!

```

### 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`:

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

## Options

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