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>
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>
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/
localVariable
at runtime. I tried using the object notations, but didn't work. Is it possible? I want to do something like this: ${( $data.localVariable = testObject.name ),''}
testObject
is the response from the server which I'm operating on in my template. TIA.
Nov 7, 2014 at 6:49
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 :-)
["test"]
? A quick search for array constant expression didn't appear to be helpful.
Feb 28, 2011 at 23:17
["test"]
for the value of the loop variable - it just has to be an array, with one value in it :-)