If statement comparing variable from index.html and posts

I have a variable in the mainpage.html front matter that is:

  - name: xxx
    title: yyy
    tag: sports

  - name: aaa
    title: bbb
    tag: ccc

in _posts front matter I have:
category: xxx

in _include/card I want to make an if statement like this:

{% if site.data.categories.name === posts.category %}
  {{ site.data.categories.tag }}
{% endif %}
output: sports

How can I do this? I’m not sure how I can reach a variable that is in the mainpage.html located in the root directory when I want the output to be in _include/card.

I don’t think you can access front matter from a different page.

Can you put that same data in the config file? then you could access it as site data. Or put it in a data file.

1 Like

Thanks! I went for a data file.

1 Like