Sunday, 15 September 2013

handlebars.js - Web-resources from javascript -



handlebars.js - Web-resources from javascript -

i need handlebars templates in javascript. create template file in tpl folder , wrote such line in xml

<resource type="download" name="tpl/" location="/tpl"/>

if set image folder can css

.css { background: url(tpl/image.png); }

if want image js ajs.$("css").css("background", "url(tpl/image.png)") have error - file not found;

image file example.. in real need template

ajs.$.ajax({ url: "tpl/backlog_coll.handlebars", cache: true, success: function(data) { source = data; template = handlebars.compile(source); $('#backlog_coll').html(template); } });

here's how that

i write function in accessible js file (lets phone call global.js now) shown below

global.js

function fngettemplate(strname) { if (handlebars.templates === undefined || handlebars.templates[strname] === undefined) { $.ajax({ url : "tpl" + strname + ".handlebars", success : function(data) { if (handlebars.templates === undefined) { handlebars.templates = {}; } handlebars.templates[strname] = handlebars.compile(data); }, async : false }); } homecoming handlebars.templates[strname]; }

this assuming have handlebars js library (something handlebars-v1.3.0.js) referred appropriately.

then within view need template show up, declare template shown below

template: fngettemplate("backlog_coll");

inside render function of view phone call template supplying needed info show below

render: function() { this.$el.html(this.template(data)); }

hope helps

handlebars.js jira-plugin atlassian webresource

No comments:

Post a Comment