var template = Handlebars.compile("Handlebars <b>{{doesWhat}}</b>");
// execute the compiled template and print the output to the console
console.log(template({ doesWhat: "rocks!" }));
</script>{{</highlight>}}
## Basics
The arguments of this template function can be accessed within curly braces and supports full js objects that may be accessed with dot notation just like you'd expect.
The "evaluation context" may be switched using "{{#with something}}{{/with}}" or "{{#each something}}{{/each}}" for looping over some list.
There is also template comments using the syntax "{{! }}" or "{{!-- --}}" to allow "mustaches like }}".
Handlebars comments will be stripped when rendering, but html comments passes through.
## Helpers and Partials
Handlebars helpers enable you to register javascript functions that may run inside templates.
To register a helper run;
{{<highlightjs"lineNos=false">}}Handlebars.registerHelper('name', function (string) {return 'SomeString'}){{</highlight>}}
This function may use the evaluation context as "this" within the function.
Or to make it a block helper, take two arguments;
{{<highlightjs"lineNos=false">}}Handlebars.registerHelper('name', function (items, options) {return 'SomeString'}){{</highlight>}}
The normal helpers are called by "{{helpername [args...]}}".
Block helpers switch the evaluation context.
The helper function for these always take options and usually context as arguments.
You can also register partials like helpers with;
{{<highlightjs"lineNos=false">}}Handlebars.registerPartial('name', 'template string with {{blocks}}'){{</highlight>}}
It should be noted that handlebars by default html escapes all results from these blocks/helpers.
If you want to avoid this then "triple mustaches" is what you're looking for.
Calling any helper function like "{{{helpername}}}" will bypass the html escaping.