Appframe Knowledge Base

1 hits

Using af.common.runTemplate - Generating html with data using a template

/* Calling af.common.runTemplate passing a template and an object containing the data you want
   in your template and/or an object of custom handlers that should be run when the templates
   is replacing the field having that name. Values in the data object get escaped, while the
   return values of any custom handlers do not. Custom handlers are used instead of data if present. */

var vTemplate, vResult, vData = { ID: "TheDivId", Text: "A test text string" };
vTemplate = '<span id="<%=ID%>"><%=Text%> - <a href="<%=Link%>">Click me</a></span>';

vResult = af.common.runTemplate(vTemplate, vData, {
    Link: function(data) {
		// Note: passing data from database into a javascript link like this
		// could result in XSS security holes if not escaped. Be careful!
		return "javascript:alert('" + data.Text + "');";

common web · Perma link post comment Posted by: Jan Henrik Endsjø Høiland (05-okt-2012)