Skip to content

fffunction/nunjucks-capture

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

nunjucks-capture

A nunjucks port of the Liquid Capture tag

Build Status Coverage Status Greenkeeper badge

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

About

๐Ÿ“ A nunjucks port of Liquids capture tag

Resources

License

Stars

Watchers

Forks

Packages

No packages published