PDA

View Full Version : Separating XTemplate Parts



thething
29 Jun 2010, 4:40 AM
Hello guys,

i would like to ask you if this is possible: I have a XTemplate and want to separate its parts to make it reusable for user Templates. For example:




var tpl = new Ext.XTemplate(
'<table cellpadding="3" cellspacing="3" border="0" width="100%"><tbody>',
'{content}',
'<tpl for=".">',

// START: Part i want to use in another template as well

'<tr>',
'<td width="20" align="center" valign="top">',
'{[func1(values.data.n_newsnr_,values,xindex)]}',
'</td>',
'<td width="20" align="center" valign="top">',
'{[func2(values.data.c_land_iso,values,xindex)]}',
'</td>',
'<td align="left" valign="top">',
'{[func3(values.data.c_headline,values,xindex)]}',
'</td>',
'</tr>',

// End

'</tpl>',
'</tbody></table>',
{
func1: function(value,record,rowIndex) {
return value
},
func2: function(value,record,rowIndex) {
return value;
},
func3: function(value, record, rowIndex) {
return value;
}
})


I tried apply etc. but it doesnt work, i pressume that it would work if would not use the tpl for="." method. and build the rows by looping the store (as seen in GroupView), but this is not what i want to do. Are there any other options?

Thanks for your answer :)

Animal
29 Jun 2010, 5:13 AM
XTemplate also takes one String as the template.

You could build that, so



myTpl = new Ext.XTemplate("<table><tr><td>" + MyApp.myComplexTpl + "</td></tr></table>");


Where you define the property myComplexTpl in your application's top level namespace.

thething
29 Jun 2010, 6:04 AM
Thank you animal - that should do the trick :)