PDA

View Full Version : Passing data to function in an XTemplate?



ostkaka
23 Mar 2011, 7:43 AM
Hey, I need to calculate some values in an XTemplate. Have a look at the code



...
'<img src="{[this.findImage(user.Name)]}"/>', //this one does *not* work
'</br><span class="name">{user.Name}</span>', //this one works like a charm
...


Why is user.Name not accessible on the first line? The error I get is: "Uncaught ReferenceError: user is not defined"
On the second line where no function is called user.Name is accessible.

I tried adding some more {} to the code like this without any success :(



'<img src="{[this.findImage({user.Name})]}"/>', //still does not work

d5chris
23 Mar 2011, 3:27 PM
This is what you want:

'<img src="{[this.findImage(values.user.Name)]}"/>',

the 'values' is the key.

ostkaka
24 Mar 2011, 2:11 AM
Yes finally it works, thanks dude :D