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

How to do 'if siblings' then

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

I want to show something in my template if sibling pages exist... I know how to do it for children:

TWIG
{% if page.children.count() > 0 %}

But can't work out how for siblings... any ideas? I would have thought this would work:

TWIG
{% if page.siblings.count() > 0 %}

But it doesn't...

Thanks people :D

10 years ago

Hey I don't think this will work because I want to show a navigation of all sibling pages ON all the sibling pages - so this would work on all the sibling pages except the last one and so it wouldn't show the nav on the last one. I need something that just checks if there IS siblings... correct me if i'm wrong though...

10 years ago

oh, but you can just change it like that

TWIG
{% if page.isLast != true %} 
{# show nothing #}
{% else %} 
{# show siblings #}
{% endif %} 

I also think about this solution if you prefer:

TWIG
{% if page.parent.children.count() %}

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