PDA

View Full Version : Ext.Template convenience



dj
26 May 2007, 5:37 AM
I'm lazy ;) so i would like to be able to pass Ext.Template's constructor a config-object that it would apply. So i could inject the required methods for the "this." syntax of the templates.



var tpl = new Ext.Template({
html:"<div>{data:this.test}</div>",
test:function(value){
return '~' + value + '~';
}
});


or html as array:



var tpl = new Ext.Template({
html:["<div>","{data:this.test}","</div>"],
test:function(value){
return '~' + value + '~';
}
});



while you are there, you could also add a "autoCompile" flag. If it is set the template would compile itself in the constructor.

jack.slocum
26 May 2007, 10:45 AM
I am also lazy and this is what I came up with. It may even be less keystrokes. I agree though, a config option would be nice for compiling.


var tpl = new Ext.Template({
html:"<div>{data:this.test}</div>",
test:function(value){
return '~' + value + '~';
}
});


var tpl = Ext.apply(
new Ext.Template("<div>{data:this.test}</div>"), {
test: function(value){
return '~' + value + '~';
}
}
);