Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing context to a Handlebars partial

I wish to pass the parent templates context to a handlebars partial.

I register my partial in app.js with the following

Handlebars.registerPartial("lifestyles", Handlebars.templates['partials/product-lifestyles']());

I then render my partial inside my main template file like the following, passing in this as a second parameters of which I understand it should pass in the context of the parent

{>lifestyles this}}

I have a log helper which console logs a parameter, inside my partial I log out this, it returns undefined.

{{log this}}

Evidentially my context isn't being passed into my partial.

My understanding is that Handlebars supports this functionality, so what could be the reason it is not functioning?

like image 410
Jacob Clark Avatar asked Oct 03 '22 01:10

Jacob Clark


1 Answers

STHayden is right, You need two opening braces when you call a partial

{{>lifestyles this}}

This is an example of using partial templates

http://jsfiddle.net/UMBGC/16/

like image 111
MarsRobot Avatar answered Oct 12 '22 10:10

MarsRobot