Can Liquid includes generate different output in different contexts? #2570
-
|
This question might be more broadly about Liquid than Eleventy’s specific implementation of it, but: My site’s posts have a lot of figures that incorporate inline SVG, which works great on the main site, but I want to replace the SVG with PNG when those posts are published in my RSS feed and newsletter. I thought it would be a simple matter of a conditional in the figure include, something like this: {% if layout == 'layouts/rss.liquid' or layout == 'layouts/newsletter.liquid' %}
{{ PNG content here }}
{% else %}
{{ SVG content here }}
{% endif %}But in all contexts, it assumes the layout in question is the one specified in the post’s front matter. I also tried setting variables in each layout like this: {% assign offsite = true %}And then tried this in the figure include: {% if offsite %}
{{ PNG content here }}
{% else %}
{{ SVG content here }}
{% endif %}But I guess includes can’t read variables in template files? Anyway, I’m out of ideas for the moment. Suggestions would be much appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 20 replies
-
|
Yeah, I think I've found Not sure if you have a repo w/ a simple test case where I can take a look at your use case. |
Beta Was this translation helpful? Give feedback.
Yeah, I think I've found
{% assign %}will put the variable in the current page's scope, but not in layouts or other files. But setting things in front matter will propagate or data directory files or probably eveneleventyComputedwill work.Not sure if you have a repo w/ a simple test case where I can take a look at your use case.