Reference a Variable Outside of a Handlebars Each Loop

Once within an Handlebars each loop, you can no longer just reference a variable that is outside the loop.  In the example below, the first ‘ParentVariable’ will render correctly, but the one within the “each” loop won’t.  {{ParentVariable}} {{#each Users}} {{ParentVariable}} {{/each}} To use the variable within the “each” block, you’ll need to add a […]

Read More

Using Handlebars Templates

 It generally takes me a few minutes to tease out the right code on the handlebars page to get everything to work, here is the essential code for setting up a handlebars template via javascript: Template Code (Html): Javascript Code: var data = {title: “Test Title”, body: “Test Body”}, source = $(“#test-template”).html(), template = Handlebars.compile(source), […]

Read More

Handlebars Just Adds Bloat and Complication

I kind of like Handlebars for templating, but more and more, I think it’s just makes the codebase more bloated and complicated: My problems with handlebars: 1. I can’t just use my existing javascript code. For instance, I have an existing function to format a phone number, but to use this within a handlebars template,  […]

Read More

Reference a Handlebars Template From Another Template (Nesting Templates)

Within the JS file, register a new partial (note: avoid underscores with with the name of the partial, or with the template names…this seems to cause issues): Handlebars.registerPartial(“inner-template”,$(“#tpl-inner-template”).html()); In the template template that you want to include the partial in, just reference the partial with: {{> inner-template Data }} If the data isn’t showing, try […]

Read More

HTML and Encoded Characters with Handlebars

As soon as I updated some of the templating on one of my websites to handlebars, HTML code wasn’t being rendered, and I recieved odd characters in the output, like:   My Blog Name » Blog Sub Title The solution to this is instead of using the standard double bracket to insert the content, use triple brackets […]

Read More