Skip to content
Grav 2.1 is out: every page speaks Markdown. Read the announcement →

How to display array key and value

Started by Muut Archive 10 years ago · 1 replies · 1017 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 2289 9 years ago
Archive · by Muut Archive, 9 years ago
2 1501 9 years ago
Archive · by Muut Archive, 9 years ago
2 4754 9 years ago
Archive · by Muut Archive, 9 years ago
1 3570 9 years ago
Archive · by Muut Archive, 9 years ago
3 1627 9 years ago