fabrizim
22 May 2008, 5:07 AM
Hi All-
Just a quick bit of info to hopefully save people some time.
When using Ext.XTemplate, I ran into some strange behavior when assign certain attributes to elements that had me puzzled for a while. It seems that src attributes for img tags, or href attributes for a tags are not always output as the extract string given. For example:
var data = {url:'some/relative/url'};
var tpl = new Ext.XTemplate('<img src="{url}" />');
var output = tpl.applyTemplate(data);
The above code will modify the url to an absolute url, and that is not always the desired behaviour.
To avoid this behaviour, you can change the quote style for the attribute from double quotes to escaped single quotes;
var data = {url:'some/relative/url'};
var tpl = new Ext.XTemplate('<img src=\'{url}\' />');
var output = tpl.applyTemplate(data);
This code will use the literal string provided in the data as the attribute value.
I have had to use this technique several times, for several tags, and it seems to work consistently.
Hope this helps someone out!
Best Regards-
Mark
Just a quick bit of info to hopefully save people some time.
When using Ext.XTemplate, I ran into some strange behavior when assign certain attributes to elements that had me puzzled for a while. It seems that src attributes for img tags, or href attributes for a tags are not always output as the extract string given. For example:
var data = {url:'some/relative/url'};
var tpl = new Ext.XTemplate('<img src="{url}" />');
var output = tpl.applyTemplate(data);
The above code will modify the url to an absolute url, and that is not always the desired behaviour.
To avoid this behaviour, you can change the quote style for the attribute from double quotes to escaped single quotes;
var data = {url:'some/relative/url'};
var tpl = new Ext.XTemplate('<img src=\'{url}\' />');
var output = tpl.applyTemplate(data);
This code will use the literal string provided in the data as the attribute value.
I have had to use this technique several times, for several tags, and it seems to work consistently.
Hope this helps someone out!
Best Regards-
Mark