eleventy icon indicating copy to clipboard operation
eleventy copied to clipboard

Allow custom filters in Liquid partials in strictVariables mode

Open vrugtehagel opened this issue 1 year ago • 0 comments

This is fixing https://github.com/11ty/eleventy/issues/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, https://github.com/11ty/eleventy/pull/3212, is related, and if the page and eleventy variables are intended to be accessible from {% render %} partials, then this PR may be dismissed.

vrugtehagel avatar Feb 23 '24 12:02 vrugtehagel