assemble / assemble-handlebars

Assemble engine plugin for Handlebars templates
https://github.com/assemble/assemble
MIT License
8 stars 19 forks source link

Add root context lookup #18

Closed shootaroo closed 7 years ago

shootaroo commented 10 years ago

Access to root context in partial by {{root}}.

ex.


---
name: foo
bar:
  name: bar

---
{{name}}
{{> leaf bar}}

leaf.hbs:
{{name}} {{root.name}}

of

foo
bar foo

See https://github.com/wycats/handlebars.js/pull/525#issuecomment-25759857

doowb commented 10 years ago

This looks nice. I'll take a look at it and run it through some assemble tests tomorrow.

Thank you.

doowb commented 10 years ago

@shootaroo sorry, I lost track of this PR since it's in a repo that we don't have a lot of activity on. I'm testing it today to see how it works out. Thanks again for the PR.

shootaroo commented 10 years ago

:clap:

jonschlinkert commented 10 years ago

see: https://github.com/wycats/handlebars.js/commit/f650b0d69ec70f82fc58022a530b95b0e4371f1d

shootaroo commented 10 years ago

@jonschlinkert thanks! I tried the {{@root}}, but there was a case that does not work.

I'll try to check it whether the case what.

shootaroo commented 10 years ago

The cause was that options.data is not over the handlebars.compile.

It is all right only the following modifications when applicable the {{@root}}.

-        tmpl = handlebars.compile(tmpl, options);
+        tmpl = handlebars.compile(tmpl, _.defaults({data: true}, options));
doowb commented 10 years ago

Okay, I see now. I think we can make that change, but we want to leave out the custom name lookup and use the latest handlebars that has @root.

shootaroo commented 10 years ago

@doowb Is good. I wait for the new release of handlebars.

doowb commented 7 years ago

Closing since we've updated to Handlebars 4 and we can use the {{@root}} property.