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

Displaying stuff only if page has children

Started by Muut Archive 10 years ago · 3 replies · 658 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 2590 9 years ago
Archive · by Muut Archive, 9 years ago
2 1705 9 years ago
Archive · by Muut Archive, 9 years ago
2 4998 9 years ago
Archive · by Muut Archive, 9 years ago
1 3828 9 years ago
Archive · by Muut Archive, 9 years ago
3 1811 9 years ago