Skip to content

Commit

Permalink
added: helpers example
Browse files Browse the repository at this point in the history
  • Loading branch information
emaphp committed Oct 20, 2014
1 parent c2aa5a9 commit 2e7a6b5
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,43 @@ return compiled({name: "world"});
<em>how are you?</em>
```


<br/>
**Adding helpers**

```javascript
//file: helpers.js

//get handlebars instance
var Handlebars = require('handlebars-template-loader').Handlebars;

Handlebars.registerHelper('list', function(items, options) {
var out = "<ul>";

for(var i=0, l=items.length; i<l; i++) {
out = out + "<li>" + options.fn(items[i]) + "</li>";
}

return out + "</ul>";
});

Handlebars.registerHelper('link', function(text, url) {
text = Handlebars.Utils.escapeExpression(text);
url = Handlebars.Utils.escapeExpression(url);

var result = '<a href="' + url + '">' + text + '</a>';

return new Handlebars.SafeString(result);
});
```

```javascript
//file: app.js

//include app helpers
require("./helpers.js");
```

<br/>
###License

Expand Down

0 comments on commit 2e7a6b5

Please sign in to comment.