Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I declare local/temp variables within a jQuery template?

Is it possible to declare new variables within the jQuery template syntax? I'm hoping to achieve the equivalent of this (which does not work):

{{var test = "test"}}

<div>
    ${test}
</div>
like image 641
Wilco Avatar asked Feb 28 '11 21:02

Wilco


2 Answers

I know this has already been answered and accepted, but here is another solution:

${( $data.localVariable = 'SOMETHING' ),''}

A jsFiddle example: http://jsfiddle.net/brettwp/PrfZ5/

like image 76
Brett Pontarelli Avatar answered Oct 03 '22 20:10

Brett Pontarelli


This is pretty lame, but one trick that might work is:

  {{each(i, test) ["test"]}}
    blah blah ${test} blah
  {{/each}}

I'm not 100% sure however about using an array constant expression like that; I'll set up a fiddle. (edit yes it works :-)

like image 21
Pointy Avatar answered Oct 03 '22 19:10

Pointy