I’m writing conditional statements to render different content on the same template.
I’d like to show different data if the page is a subpage of a certain page template foo.
<?php if ($page->parent()->template('foo')) : ?>
<h3> a list of things when it is a grandchild…</h3>
<?php else : ?>
<h3> a list of things when it is a child…</h3>
<?php endif ?>
I’ve searched and checked out the filter and filterBy pages, but not finding a solution yet.
Should I just be checking to see if the URL contains /foo/?
Or maybe I should be checking to see if the parent is Home, else…
Solved it using the second method (check if parent is Home, by checking if page has a Parent count of more than 0).
After reading this:
<?php if ($page->parents()->count() > 0) : ?>
I decided to check using that method (if page has parent count greater than 0). This works, but I’d still love a better method. I like that it works, but I fear it’s using incorrect logic and would break if the site structure would grow beyond this.