 <p>Handlebars is a minimal tempting language for JavaScript and as such it will not let you execute arbitrary code from within a template. Handlebars does however provide you with helpers let you execute pre-defined code over your template. The built in ones are: <code>each</code>, <code>unless</code>, <code>if</code> and <code>else</code>.</p> <p>You can create your own helpers with the <code>Handlebars.registerHelper</code> method. Here is a simple example that formats a phone number. So long as you register the helper before you call it you should be able to use <code>{{formatPhoneNumber phoneNumber}}</code> anywhere in your code.</p> <pre><code>Handlebars.registerHelper("formatPhoneNumber", function(phoneNumber) { phoneNumber = phoneNumber.toString(); return "(" + phoneNumber.substr(0,3) + ") " + phoneNumber.substr(3,3) + "-" + phoneNumber.substr(6,4); }); </code></pre> <p>Note: While it may be technically possible to execute non-rendering code from within a helper, this is considered bad practice and should be avoided if at all possible.</p>