View Full Version : custom function in tpl?

28 Aug 2009, 5:28 PM
Not sure where to start as this is almost tricky...

In my dataview tpl I would like to use a custom function. I have the function written and it works perfect, problem is I need to call it from the tpl. I really do not see a way to do this though.

Here is some code :)

my function...

function thumbLink (val) {
url : 'lightshow.php?folder=' + val,
method: 'POST',
success: function ( result, request ) {
var newThumb = result.responseText;
failure: function ( result, request ) {
console.log(result, 'Error');
}the tpl - {aname} is where I need to call the function! - or put the result there...

var profiletpl = new Ext.XTemplate(
'<tpl for="."><table style="text-align: left; width: 796px;" cellpadding="2" cellspacing="2">',
'<td style="width: 162px;" colspan="1" rowspan="4">{aname}</td>',
'</table></tpl>');and the view...

var profileView = new Ext.Panel({
width: 800,
frame: true,
autoHeight: 'true',
collapsible: true,
animCollapse: true,
title: 'Profile View',
renderTo: 'profile',
items: new Ext.DataView({
itemSelector: '.clickable',
store: profileDB,
tpl: profiletpl

No need to post the store I guess. Not sure how to approach this. This template is a one-shot and loads with the store.


28 Aug 2009, 8:04 PM
There's an example of exactly that in the docs, it passes a custom method to the tpl constructor.

28 Aug 2009, 8:55 PM
I will read it again...


29 Aug 2009, 3:30 AM
It's quite difficult to get template right.

The thing to do is play with them on the Firebug xonsole command line creating small templates and running them util you get the technique right.

Try this on the Firebug console:

new Ext.XTemplate('<tpl for=".">{[this.foo(values)]}</tpl>', { foo: function(v){return 'bar = "' + v.bar + '"';}}).apply({bar:'bletch'})