Skip to content

Allow custom filters in Liquid partials in strictVariables mode #3213

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

Merged

Conversation

vrugtehagel
Copy link
Contributor

@vrugtehagel vrugtehagel commented Feb 23, 2024

This PR fixes #3206.

The issue here is that in partials rendered using {% render %}, the page and eleventy variables do not exist, since the {% render %} tag is introducing a "new" scope that does not inherit the variables from the page it was called from. In strictVariables mode (this is an option you can pass to .setLiquidOptions()), this causes an error when you use any custom filter in such a partial, because Eleventy is trying to retrieve the value of the page and eleventy globals for use in the filter's definition.

This PR essentially turns the properties page and eleventy into getters; meaning that they are not retrieved until the user specifically uses them. This prevents filters that do not use these properties from causing errors in {% render %}-style partials.

My other PR, #3212, is related, and if the page and eleventy variables are intended to be accessible from {% render %} partials, then this PR may be dismissed.

@zachleat zachleat merged commit a9985e4 into 11ty:main Apr 9, 2024
@zachleat zachleat added this to the Eleventy 3.0.0 milestone Apr 9, 2024
@zachleat
Copy link
Member

zachleat commented Apr 9, 2024

Shipping with 3.0.0-alpha.6. Thank you!

@vrugtehagel vrugtehagel deleted the strict-variables-and-filters-in-includes branch April 9, 2024 17:39
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

Successfully merging this pull request may close these issues.

Strict variables and custom filters in includes
2 participants