Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Because you've only defined an interpolation regex in your custom template settings, underscore doesn't know when to evaluate expressions. When you define custom template settings you need to define and differentiate between interpolation and evaluation. From the underscore <code>template()</code> documentation: </p> <blockquote> <p>Define an interpolate regex, and an (optional) evaluate regex to match expressions that should be inserted and evaluated, respectively. If no evaluate regex is provided, your templates will only be capable of interpolating values.</p> </blockquote> <p>In a standard (no custom settings) template the difference is evaluation: <code>&lt;% %&gt;</code> and value interpolation: <code>&lt;%= %&gt;</code>.</p> <p>So, for example, your template above should be (with standard template settings): </p> <pre><code>&lt;% _.each([0,1,2,3,4], function(i) { %&gt; &lt;p&gt;&lt;%= i %&gt;&lt;/p&gt; &lt;% }); %&gt; </code></pre> <p>If you want to continue using custom settings you'll need to define an evaluation regex in _.templateSettings as well. Based on your questions and comments something like:</p> <pre><code> _.templateSettings = { interpolate: /\&lt;\@\=(.+?)\@\&gt;/gim, evaluate: /\&lt;\@(.+?)\@\&gt;/gim }; </code></pre> <p>And then update your template to use the evaluation form around code blocks and the interpolation form around values, like so:</p> <pre><code>&lt;script type="text/template" id="pageContent"&gt; &lt;div class="col2"&gt; &lt;@ _.each([0,1,2,3,4], function(i) { @&gt; &lt;p&gt;&lt;@= i @&gt;&lt;/p&gt; &lt;@ }); @&gt; &lt;/div&gt; &lt;/script&gt; </code></pre> <p>source: <a href="http://documentcloud.github.com/underscore/#template" rel="noreferrer">http://documentcloud.github.com/underscore/#template</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload