1
0
mirror of https://github.com/onkelbeh/cheatsheets.git synced 2026-08-15 21:44:51 +02:00
Files
cheatsheets/handlebars.js.md
Rico Sta. Cruz 1e78ce422b Update weights
2017-08-30 05:53:47 +08:00

563 B

title, category, layout, weight
title category layout weight
Handlebars.js JavaScript libraries 2017/sheet -1

{% raw %}

Helpers

Handlebars.registerHelper('link_to', function() {
  return "<a href='" + this.url + "'>" + this.body + "</a>";
})
var context = { posts: [{url: "/hello-world", body: "Hello World!"}] }
var source = "<ul>{{#posts}}<li>{{{link_to}}}</li>{{/posts}}</ul>"
var template = Handlebars.compile(source)
template(context)

Would render:

<ul>
  <li><a href='/hello-world'>Hello World!</a></li>
</ul>

{% endraw %}