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

Displaying stuff only if page has children

Started by Muut Archive 10 years ago · 3 replies · 545 views
10 years ago

I'd like to test if a page has children and showing html content only if it has children.

TWIG
{% set sub_sub_sections = sub_section.children %}

this is the test, but it renders the html content anyway ... :(

TWIG

{% if sub_sub_sections %}
  <div>html</div>
{% endif %}
---
10 years ago

I have not tested yet, but this should work:

TWIG
{% if sub_sub_sections|length > 0 %}
  <div>html</div>
{% endif %}
10 years ago

or maybe like this:

TWIG
{% if sub_sections.children.count() > 0 %}
  <div>html</div>
{% endif %}

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 2955 9 years ago
Archive · by Muut Archive, 9 years ago
3 1121 9 years ago