Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/marceljs/nunjucks-embed
- Owner: marceljs
- License: mit
- Created: 2019-08-02T11:48:09.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-04T05:45:56.000Z (almost 2 years ago)
- Last Synced: 2024-04-28T06:07:47.211Z (7 months ago)
- Topics: nunjucks, nunjucks-custom-tag, twig
- Language: JavaScript
- Size: 188 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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