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

Clay Handlebars uses the Root Handlebars Environment #51

Open
yuliyv opened this issue May 21, 2018 · 3 comments
Open

Clay Handlebars uses the Root Handlebars Environment #51

yuliyv opened this issue May 21, 2018 · 3 comments
Labels

Comments

@yuliyv
Copy link

yuliyv commented May 21, 2018

Setup

In your package json have two different packages which both depend on clayhandlebars (for example amphora-html and amphora-amp) and within each of those packages have something like the following:

var clayhandlebars = require('clayhandlebars'),
  hbsEnvironment = clayhandlebars();

Expected Result

The two packages should have non-conflicting hbsEnvironments, i.e that hbsEnvironment in both packages should be a separate Handlebars environment

Actual Result

Both packages have the same hsbEnvironment meaning they can potentially conflict when defining partials or helpers. I believe this is due to the fact that clayhandlebars will define the environment by just requiring the handlebars package (which will get cached by require). This causes an issue if the two packages intend to add partials of the same name

Possible Resolution

One possible resolution I think would be to make a slight modification to the way the environment is created. In the initialization method change the handlebars initialization to use create so that it always produces a no-conflict handlebars environment to use.

@nelsonpecora
Copy link
Contributor

I like this idea, but I'm worried about how different packages are using handlebars (I know kiln has to do some weird stuff to mimic using the same hbs environment / helpers / partials as amphora-html)

@yuliyv
Copy link
Author

yuliyv commented May 21, 2018

In the interim time I could utilize the env override here and pass in my own handlebars environment in amphora-amp so that it does not utilize the root one. Is that what you'd recommend for now?

@nelsonpecora
Copy link
Contributor

Yeah, I think that's a good workaround for now.

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

No branches or pull requests

3 participants