False value in page header returns nothing

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.

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

{{ 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 :slight_smile:

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.

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