Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{{root}} helper doesn't work as intended in all situations #138

Open
Vlasterx opened this issue Sep 9, 2017 · 6 comments
Open

{{root}} helper doesn't work as intended in all situations #138

Vlasterx opened this issue Sep 9, 2017 · 6 comments

Comments

@Vlasterx
Copy link

Vlasterx commented Sep 9, 2017

It seems that Panini specific helper {{root}} doesn't always work as intended.

Take this folder structure for example:

/site/
  |-data/
    |-galery.yml
  |-pages/
    |-en/
      |-test_page.html

Data galery.yml is just a list of image URL's

If I use {{root}} from withing an article located in /pages/en/test-page.com and if I don't wrap it in some other Panini helpers - it will work as intended, but if I use it like this

{{#each galery.team }} <p>Image root: {{root}}</p> {{/each}}

It will not work at all.

@Vlasterx Vlasterx changed the title {{root}} helper doesn't work {{root}} helper doesn't work as intended in all situations Sep 9, 2017
@gakimball
Copy link
Contributor

Could you see if writing {{../root}} works instead? Might be a Handlebars quirk.

@Vlasterx
Copy link
Author

Vlasterx commented Sep 14, 2017

Doesn't that defeat the purpose of {{root}} helper? What if I put that code in a partial that could be used in files that reside in different directory levels?

It seems that path is not passed along properly with each helper.

@gakimball
Copy link
Contributor

gakimball commented Sep 14, 2017

The ../ isn't related to the path of the root variable, it's a Handlebars thing.

Handlebars has scopes, and some helpers create a new scope. This means you can't access variables in the parent scope just by writing them normally. Adding the ../ means you want to access a variable in the parent scope.

Does that make sense?

@Vlasterx
Copy link
Author

Yes, thank you gakimball, this makes sense. I will try it out.

@bloomdigital
Copy link

@Vlasterx did you ever find a fix for this? Having the same issue myself

@Vlasterx
Copy link
Author

Vlasterx commented Feb 10, 2020

@daaanpace yes, I had to reorganize my markup and abandon the use of {{root}} in this particular case.

Data - galery.yml

-
  image: images/work/0-new/13
  title: Some title
  more: textile/new.html
-
  image: images/work/1-textile-art
  title: Some title
  more: textile/more.html
-
  image: images/work/1-prints
  title: some title
  more: prints/more.html
-
  image: images/work/0-new/21
  title: some title
  more: textile/new.html

Partial - galery-part.html

  <a href="/{{this.image}}.jpg"
     title="{{#if this.more}}<a href='/{{ this.more }}' class='galery__info'><span class='icon icon-image'></span> More</a>{{/if}}
     {{#if this.buy}}<a href='{{ this.buy }}' class='galery__buy'><span class='icon icon-cart'></span> Buy</a>{{/if}}
     {{this.title}}"><img src="/{{this.image}}_th.jpg" srcset="/{{this.image}}_th.jpg 1x, /{{this.image}}[email protected] 2x" alt="{{ this.title }}"/></a>

Page - galery.html

---
(all front-matter stuff)
---

<section class="masonry">
{{#each galery}}
  {{> galery_part}}
{{/each}}
</section>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants