clay / handlebars

A collection of helpers and partials for handlebars
MIT License
15 stars 8 forks source link

Clay Handlebars uses the Root Handlebars Environment #51

Open yuliyv opened 6 years ago

yuliyv commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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