Guides
Tutorials
Pop Tags

Enclosed

For manipulating a portion of your template.

If you open up an extension tag in your template, you can access an object that represents the part of the template which is inside of the extension tag by using the enclosed parameter.

Enclosed has two methods:

enclosed.tags() Returns an array of PopTag nodes within the enclosed portion of the template. A node is either an object representing a Pop Tag, or a string representing the portion of a template in-between Pop Tags.
enclosed.render() Returns the enclosed template as a string of html.

Here’s a simple extension method that will repeat the enclosed template:

/extensions/example.js

exports.repeat = function(options, enclosed) {
  var times = options.times ? parseInt(options.times, 10) : 1;
  var result = []
  for (var i=0; i < times; i++) {
    result.push(enclosed.render());
  }
  return result.join("");
};

If used like this:

<pop:example:repeat times="3">
  <h2>Hello</h2>
</pop:example:repeat>

The output would be:

<h2>Hello</h2><h2>Hello</h2><h2>Hello</h2>
Continue to Scope »