nunjucks-capture

1.0.4 • Public • Published

nunjucks-capture

A nunjucks port of the Liquid Capture tag

Build Status Coverage Status

Install

npm install nunjucks-capture

Usage

Add the extension to the Nunjucks environment:

var nunjucks = require('nunjucks');
var CaptureTag = require('nunjucks-capture');
 
var env = new nunjucks.Environment();
env.addExtension('CaptureTag', new CaptureTag());

Capture some content as a string:

{% capture as="demo" -%}
    <h2>Hello, world!</h2>
    {% include 'includes/content.html' %}
{%- endcapture %}
 
{{ demo }}
 
<pre>
    {{ demo | e }}
</pre>
 

will result in:

<h2>Hello, world!</h2>
<p>This is the included content</p>
<pre>
    &lt;h2&gt;Hello, world!&lt;/h2&gt;
    &lt;p&gt;This is the included content&lt;/p&gt;
</pre>

Everything between the two tags is stored in a new variable as a string. Dynamic content, such as includes or loops, are evaluated before the variable is stored. This means you've captured the resulting content, not the templating.

See also: - Nunjucks API documentation - Nunjucks templating documentation

Built by fffunction, with love and coffee

Readme

Keywords

Package Sidebar

Install

npm i nunjucks-capture

Weekly Downloads

3

Version

1.0.4

License

MIT

Last publish

Collaborators

  • danreeves