Skip to content
● Grav 2.2 is out: 2x faster cold starts and 96% less memory on big sites. Read the announcement →

How to display array key and value

Started by Muut Archive 10 years ago · 1 replies · 1057 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 2590 9 years ago
Archive · by Muut Archive, 9 years ago
2 1705 9 years ago
Archive · by Muut Archive, 9 years ago
2 4997 9 years ago
Archive · by Muut Archive, 9 years ago
1 3826 9 years ago
Archive · by Muut Archive, 9 years ago
3 1810 9 years ago