I have a section with a "Structure" section type. I've called it "structure_casestudies".

I'd like to create a navigation bar that links to that page, but only if there is at least one entry within it.

hasDescendants() or similar EntryModel functions work fine, for structure pages only. But how can I perform the same check, from anywhere on the site?

I hoped doing a specific query would do the trick... but this just isn't right.

{% if craft.entries.section('structure_casestudies').hasDescendants() %}<a href="#">Case Studies</a>{% endif %}

Any ideas?

2 Answers 2


To do a check if a structure has content you could do

{% set structureNav = craft.entries({ section : 'structure_casestudies' }).first() %}

{% if structureNav != "" %}
    I exist.
{% else %}
    I don't exist.
{% endif %}
  • Nice, Thanks Mart. I just had to add ".first()" to get this working. {% set structureNav = craft.entries({ section : 'structure_casestudies' }).first() %} Sep 2, 2014 at 13:21

I like to keep a neat collection of useful functions, so I've just 'converted' the above, with a php based plugin function.

public function hasChildren($section) {
 $criteria = craft()->elements->getCriteria(ElementType::Entry);
 $criteria->section = $section;
 return $criteria->count();

echo $this->hasChildren('structure_services') ? "I Exist." : "I Don't exist.";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.