Can I call a jekyll page attribute within a for statement

32 Views Asked by At
{% for item in site.data.{{page.ocean}}.section %}

This is not working for me. I'm using page.ocean at other places in the page and it works fine. I'm not sure if I can do this within a for statement. If not, is there a way to work around it?

1

There are 1 best solutions below

0
Dhanu Gurung On

Try this:

{% assign ocean = page.ocean %}
{% for item in site.data[ocean].section %}
  <!-- your code -->
{% endfor %}

Check Liquid's Variable and yes we can access data variable content like an Array through indexing.