Handlebars-Contrib
Underscore-contrib style library but for handlebars. Provide some common handlebars
helper functions for use in templates. They are split out by feature area.
Features
- String helpers
- Math helpers
Build Status
About
Underscore contrib style handlebars helper functions. Adds helper functions to your handlebars templates as well as in your javascript.
Source
This is an open source project hosted on github. The source is available here.
String Helpers
Capitalize
Capitalize the first character of the first word in the string.
{{capitalize this.firstName}}
Capitalize All
{{capitalize-all this.name}}
Normalize Spaces
{{normalize-spaces this.summary}}
To URL Slug
<a href="localhost/blog/{{to-url-slug this.postTitle}}">post</a>
Match
This helper is a conditional and fully supports the else
clause.
<!-- commonNameRegex = /^John/, for example -->
{{#match this.name this.commonNameRegex}}
<p>What a common name!</p>
{{else}}
<p>What a unique name!</p>
{{/match}}
Math Helpers
While you can use these in javascript, they are really designed for use within the templates. The calculate method in javascript would be easier to do it directly.
Calculate
The supported operators are [+, -, /, *, %]
{{calculate this.costOfCookies '+' this.costOfMilk}}
{{calculate this.totalPrice '*' this.taxRate}}
Compare
This helper is a conditional and fully supports the else
clause. The supported operators are [<, <=, >, >=, ==, !=, ===, !==]
.
{{#compare this.price '<=' this.budget}}
<p>Affordable</p>
{{else}}
<p>Too expensive :(</p>
{{/compare}}