PDA

View Full Version : xtemplate definitions config



ttbgwt
13 Jun 2012, 6:04 AM
Can someone explain how xtemplate definitions can be used? I've tried searching google and the forums but have not had any luck...

http://docs.sencha.com/ext-js/4-1/#!/api/Ext.XTemplate-cfg-definitions

burnnat
14 Jun 2012, 11:19 AM
Here's a pretty contrived example of a definitions config in use:

new Ext.XTemplate(
'Value is {value}. ',
'Multiplier is {[multiplier]}. ',
'Result is {[multiplier * values.value]}.',
{
definitions: 'var multiplier = 2;'
}
).apply({
value: 10
}); // "Value is 10. Multiplier is 2. Result is 20."

As far as I can tell, it's basically the same as using a "verbatim" block at the start of your template, like so:

new Ext.XTemplate(
'{% var multiplier = 2; %}',
'Value is {value}. ',
'Multiplier is {[multiplier]}. ',
'Result is {[multiplier * values.value]}.',
).apply({
value: 10
}); // "Value is 10. Multiplier is 2. Result is 20."

I have no idea what a practical use case for this would be, though. I've never had to use one personally.