Moe-js v0.3

Capture Blocks

Capture blocks let you redirect the output of a template to a variable.

For example the following causes the content of the capture block to be rendered to a string and stored in the variable userNameParagraph.

{{#capture var userNameParagraph}}
<p>Model.UserName</p>
{{/capture}}

This variable can then be used elsewhere in the template:

{{userNameParagraph}}

Capture blocks can also be used to pass additional content to an outer layout by storing additional content on the model object:

{{#capture model.userScripts}}
   <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.16.0/prism.min.js"></script>
{{/capture}}

The layout file might then look something like this:

<html>
<head>
{{#if model.userScripts}}
{{{model.userScripts}}}
{{/if>}}
</head>
<body>
{{{model.body}}}
</body>
</html>