PDA

View Full Version : Template syntax documentation?



wakeup
28 Jun 2010, 3:33 AM
Hey guys,
Is there a way to not just include json field-variables in templates but also arbitrary JS?

Example: {var t = Date.parse(t_start); t.hours + ":" + t.minutes;} instead of {t_start} in:

tpl: [
'<tpl for=".">',
'<div class="track_list">',
'<div class="track_start">{t_start}</div>',
'<div class="track_performer">{performer}</div>',
'-',
'<div class="track_title">{name}</div>',
'</div>',
'</tpl>'
]

cheers,
max

TommyMaintz
28 Jun 2010, 12:53 PM
One way of adding custom formatting functions to your templates:


tpl: [
'<tpl for=".">',
'<div class="track_list">',
'<div class="track_start">{t_start:this.customFormat}</div>',
'<div class="track_performer">{performer}</div>',
'-',
'<div class="track_title">{name}</div>',
'</div>',
'</tpl>',
{
customFormat : function(value) {
var t = Date.parse(value);
return t.hours + ':' + t.minutes;
}
}
]


However, we provide date formatting inside templates out of the box. You could specify your template as follows:


tpl: [
'<tpl for=".">',
'<div class="track_list">',
'<div class="track_start">{t_start:dateFormat("h:i")}</div>',
'<div class="track_performer">{performer}</div>',
'-',
'<div class="track_title">{name}</div>',
'</div>',
'</tpl>'
]