Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

How to display array key and value

Started by Muut Archive 10 years ago · 1 replies · 910 views
10 years ago

Hi, I have an array in my config.site yaml like so:

YAML
mobile_nav:
  'Our School': /our-school
  'Our Community': /our-community
  Gallery: /gallery
  Contact: /contact

How do I get the key and value? I tried this:

TWIG
{% for item in site.mobile_nav %}
  <li><a href="">{{ key }} {{ value }}</a></li>
{% endfor %}

But it doesn't display either. If I put this it displays the value only:

TWIG
{% for item in site.mobile_nav %}
  <li><a href="">{{ item }}</a></li>
{% endfor %}

I also tried:

TWIG
{% for array in site.mobile_nav %}
  <li><a href="">{{ key }} {{ value }}</a></li>
{% endfor %}

And also these inside the loop {{ array.key }} {{ item.key }} etc but nope.

What am I doing wrong?

Also as a side note, Grav add's inverted comma's arround the ones that have 2 words and no '' around the ones with single words.

Thanks

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1359 9 years ago
Archive · by Muut Archive, 9 years ago
2 936 9 years ago
Archive · by Muut Archive, 9 years ago
2 4066 9 years ago
Archive · by Muut Archive, 9 years ago
1 2957 9 years ago
Archive · by Muut Archive, 9 years ago
3 1121 9 years ago