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

False value in page header returns nothing

Started by Muut Archive 9 years ago · 2 replies · 470 views
9 years ago

Hi guys,

Grav is amazing and I'm currently developing a custom theme. However I cannot get the YAML markdown in my page header to render correctly. I'm using a custom header variable to render my navigation content.

YAML
title: MyPage
show_in_navi: false

If I set 'showInNavi' to true, i can access its value in my twig template and it returns '1'. If I set it to false it returns nothing. I'm using

TWIG
{{ page.header.show_in_navi }}

What am I doing wrong here? Do I have to set a global default value in another file for every page which is not calling the custom variable? I don't want to add a 'true' in every page that should be displayed in the navigation manually... Thanks for your help :)

9 years ago

This is because false is interpreted by PHP as non-existent when evaluated. As an alternative, you could evaluate it as a string instead; show_in_navi: 'false' with {% if page.header.show_in_navi == 'false' %}.

However it is generally better that pages explicitly declare themselves as included in the menu, because otherwise pages which should not be included but where the header has not been set will be - which authors could easily do just by forgetting to set it.

A good approach would be to include show_in_navi: true as a default in blueprints, and iterate over all published pages with the header set. This avoids accidental menu-items.

9 years ago

Great! Exactly what I needed! Thank you! :)

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1321 9 years ago
Archive · by Muut Archive, 9 years ago
2 916 9 years ago
Archive · by Muut Archive, 9 years ago
2 4047 9 years ago
Archive · by Muut Archive, 9 years ago
1 2921 9 years ago
Archive · by Muut Archive, 9 years ago
3 1105 9 years ago