foundation / panini

A super simple flat file generator.
Other
592 stars 104 forks source link

Root variable not working in partials with helper data #118

Closed mmilano closed 7 years ago

mmilano commented 7 years ago

see issue #20.

mmilano commented 7 years ago

per reference in issue 20, a demo test of the issue can be seen here in the test named: Panini variables {{root}} variable that stores a relative path to the root folder: https://github.com/mmilano/panini/tree/testing-root-with-helper

gakimball commented 7 years ago

In your test repo, when you write {{> partial-p3 (helper-data)}}, you're passing in the value of helper-data as a new child context to the partial-p3 template. That means the root variable doesn't exist in the partial-p3 template, which is why you get an empty string instead of the ../../.

However, it's still possible to get to the root variable. If you write ../root instead, Handlebars will pull the root variable out of the parent context. Changing the partial-p3 template to this should do the trick:

<img src="{{../root}}{{filename~}}">

Let me know if that helps :)

mmilano commented 7 years ago

ah.

so it appears that i (and maybe some others) misapprehended "root" to be a global sort of value, available everywhere.

it looks like @root.root may work better for me. that seems to work regardless of the level.

thanks, @gakimball.

gakimball commented 7 years ago

so it appears that i (and maybe some others) misapprehended "root" to be a global sort of value, available everywhere.

Yeah, it's just how Handlebars works—I don't think there's a concept of global data.

Glad I could help! :)