javascript - Create link in handlebars.js using helper -
i have tried follow example in handlebars documentation on how create link, instructions unclear me. handlebarsjs.com/expressions.html (see "helpers")
first of all, without link helper can make link text appear on screen, text, not link.
<script id="template" type="text/x-handlebars-template"> <h4>{{{my_link}}}</h4> </script>
and text retrieved ajax request. add link keyword
<h4>{{{link my_link}}}</h4>
and nothing displayed. helper code have currently, doesn't work:
$(function(){ handlebars.registerhelper('link', function(my_link) { var url = handlebars.escapeexpression(my_link.url); var result = "<a href='" + url + "'></a>"; console.log(result); return new handlebars.safestring(result); }); });
is relevant put piece of code in javascript?
when click submit button, ajax request made , link retrieved. link helper, console.log gives empty link:
"<a href=''></a>"
since registered name of helper link
, template should start {{{link
so
<h4>{{{my_link}}}</h4>
should
<h4>{{{link my_link}}}</h4>
and
var url = handlebars.escapeexpression(my_link.url);
should changed
var url = handlebars.escapeexpression(my_link);
Comments
Post a Comment