-
-
Notifications
You must be signed in to change notification settings - Fork 237
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
Define global objects which can be accessed by render tag #185
Comments
At first glance it seems something contradictory: we need to make the variables passed down explicit, and we need globals at the same time. But I'll try to be compatible with the shopify liquid and dig into that behaviour to make sure it's intended. And I prefer to the second way (in which you can define a object literal to specify the globals). |
Try [email protected], it should be supported by passing globals option. |
Thanks @harttle; started working with this, and all seems to work as expected. Will file any bugs/issues if I come across them. Thanks so much for adding this feature so quickly! |
@harttle is there a way to get globals option to work with Express Liquid integration? https://liquidjs.com/tutorials/use-in-expressjs.html I feel like i'm going down a rabbit hole here, I understand the express |
I think I might have found a solution:
To use in an express router I had to set |
The
|
the settings object indeed does not work when using express res.render method |
@harttle please see the following repo for a minimal example of the settings object NOT working when using express res.render() https://github.com/jsuiker/liquidjs-express-globals |
@jsuiker I find expressjs passes a var app = express()
// after `express` is created, delete its `.locals.settings`:
delete app.locals.settings; |
Having experienced a few cases where variables have unintentionally leaked into included template partials, it was interested to note that Liquid (and LiquidJS) now support the stricter
render
tag, and thatinclude
has been deprecated.I tried to update my 11ty-generated site to use
render
, but in doing so, soon came across a limitation; global data objects are not available to rendered partials.For example, I have the following partial:
The data for both
app
andnavigation
comes from global data files. Given the encapsulated nature ofrender
, I have to declare these each time I wish to render this partial on a page, which is not always easy or possible within the confines of a Liquid template.Looking at the relevant Shopify theme docs, I note that:
Shopify define their own global objects, but there’s no way for an author using LiquidJS to do the same, as far as I can see.
I imagine being able to define an array of
globals
when configuring LiquidJS (shown within the context of an 11ty configuration), like so:Alternatively, perhaps an object would allow authors to define a name for each global:
Not sure which is the best approach; I have no preference.
Is this a legitimate feature request, or have I missed something?
The text was updated successfully, but these errors were encountered: