Answers.Body: <p>To do a check if a structure has content you could do</p>
  
  <pre><code>{% set structureNav = craft.entries({ section : 'structure_casestudies' }).first() %}
  
  {% if structureNav != "" %}
      I exist.
  {% else %}
      I don't exist.
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-09-02T13:21:17.173Z
Answers.Text: Nice, Thanks Mart. I just had to add ".first()" to get this working. 
  {% set structureNav = craft.entries({ section : 'structure_casestudies' }).first() %}
Answers.UserDisplayName: Mark Notton
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-09-02T12:18:03.157Z
Answers.LastActivityDate: 2014-09-02T15:04:59.747Z
Answers.LastEditDate: 2014-09-02T15:04:59.747Z
Answers.UserDisplayName: Mart
Answers.Body: <p>I like to keep a neat collection of useful functions, so I've just 'converted' the above, with a php based plugin function.  </p>
  
  <pre><code>public function hasChildren($section) {
   $criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
   $criteria-&gt;section = $section;
   return $criteria-&gt;count();
  }
  
  echo $this-&gt;hasChildren('structure_services') ? "I Exist." : "I Don't exist.";
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-09-02T16:26:42.507Z
Answers.LastActivityDate: 2014-09-02T16:26:42.507Z
Answers.UserDisplayName: Mark Notton
Body: <p>I have a section with a "Structure" section type. I've called it "structure_casestudies".</p>
  
  <p>I'd like to create a navigation bar that links to that page, but only if there is at least one entry within it. </p>
  
  <p>hasDescendants() or similar EntryModel functions work fine, for structure pages only. But how can I perform the same check, from anywhere on the site?</p>
  
  <p>I hoped doing a specific query would do the trick... but this just isn't right.</p>
  
  <pre><code>{% if craft.entries.section('structure_casestudies').hasDescendants() %}&lt;a href="#"&gt;Case Studies&lt;/a&gt;{% endif %}
  </code></pre>
  
  <p>Any ideas?</p>
  
Tags: <entrymodel>
Title: How to check structure type has any entries/children from anywhere on my site?
ThreadText: # How to check structure type has any entries/children from anywhere on my site?
  
  (Asked by: username_0 on 2014-09-02)
  
  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?
  
  **Tags:** entrymodel
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2014-09-02. Score: 2 | Accepted answer
  
  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 %}
  
  ```
  
  > **Comments:**
  > **username_0**: Nice, Thanks username_1. I just had to add ".first()" to get this working.  {% set structureNav = craft.entries({ section : 'structure_casestudies' }).first() %}  
  
  ---
  
  ### Answer by username_0 on 2014-09-02. Score: 0
  
  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.";
  
  ```
  
  
  ---
  
  