Hi all. I’m stuck on how to display a conditional statement from a collection page on a non-collection page. My file structure is a little complex, but necessary because of the way I’m implementing a multilingual website. Here is what I’ve got so far.
I am using a file in a collection to hold the content that will ultimately appear in one section of a page…
my_collection/about_section.md:
---
section_id: about_section
…
---
{% capture content_french %}
Quelques paragraphes en français.
{% endcapture %}
{% capture content_english %}
Some paragraphs in English.
{% endcapture %}
{% if include.language == "content_french" %}
{{ content_french }}
{% endif %}
{% if include.language == "content_english" %}
{{ content_english }}
{% endif %}
Then, I loop through this collection page in an _includes file that I am using to mark up the layout of the about.md file above, as well as other collection files. (I’m not sure if a parameter can be used in a variable, as shown below, but I don’t know how else to do it.)
_includes/section_layout.html:
{% for item in site.my_collection %}
{% if item.section_id == "about_section" %}
{% if page.lang == "fr" %}
{{ item.content language="content_french" }}
{% else %}
{{ item.content language="content_english" }}
{% endif %}
{% endif %}
{% endfor %}
Finally, I have two user-visible pages (one for each language), which both pull in the same _includes file (and other includes).
fr/about/index.md:
---
lang: fr
---
{% include section_layout.html %}
…
en/about/index.md:
---
lang: en
---
{% include section_layout.html %}
…
As it is, {{ item.content }} is not showing up on either the French or English page. Some other content that I put in the collection’s front matter does show up, but I’m struggling to display {{ item.content }} area with these conditions. If a secondary _includes file is needed to pull in {{ item.content }} to achieve what I want, I am willing to do that.
Ideally, in about_section.md, instead of the captures, I would like to be able to write something like the following:
{% if page.lang == "fr" %}
French content
{% else %}
English content
{% endif %}
But that doesn’t work, presumably because page.lang refers to this collection page itself, rather than the page where I want the content to appear (e.g. fr/about/index.md).
Any ideas would be appreciated. Many thanks in advance.