Layout Page Not Using Variable

I’m trying to list tags for specific categories in Jekyll. For this, I have an index page for each category. All these pages have a different variable called “category” in their front matter. And they all use the same layout page. In the layout page, I’m running this code to filter tags in specific categories.

 {% for post in site.categories['{{page.category}}'] %}
    {% for tag in post.tags %}
     {{ tag  }}
   {% endfor %}
 {% endfor %}

However this doesn’t work. If I change the [’{{page.category}}’] with the name of each category, it does what I need; but that defeats the purpose of using a layout.

I’m a total newbie in web programming and Jekyll, so apologies if this doesn’t make sense. Any help would be greatly appreciated, thanks!

Did you try:

{% for post in site.categories[page.category] %}

I’ve tried a few different formats with the brackets but it looks like I’ve missed that one. It did the trick nicely - thanks a lot!

1 Like