Answers.Body: <p><code>entry.ancestors</code> returns an ElementCriteriaModel (→ <a href="http://buildwithcraft.com/docs/templating/entrymodel#getAncestors" rel="nofollow"><code>getAncestors()</code></a> in the Craft docs) prepped to return the entry's ancestors.</p>
  
  <p><code>entry.ancestors.level(3)</code> makes it return only entry ancestors which are at 3rd level of the structure.</p>
  
  <p>As you well pointed out in the comments, an entry can only have one ancestor on a particular structure level. So you can now use the <code>first()</code> method to get this one entry. Keep in mind that if there's no ancestor at that level, the method won't return anything (<code>null</code>).</p>
  
  <pre><code>{% set ancestorL3 = entry.ancestors.level(3).first() %}
  
  {% if ancestorL3 %}
      {{ ancestorL3.title }}
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-04T17:34:31.620Z
Answers.Text: I see… I was thinking .level(3) would return a single entry as .first does (not sure how an entry could have more than one ancestor at a particular level). Thanks!
Answers.UserDisplayName: philzelnar
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-04T18:12:36.173Z
Answers.Text: @alsophil male and female?? ...errrm no.
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-04T15:42:48.960Z
Answers.LastActivityDate: 2015-02-04T18:11:17.957Z
Answers.LastEditDate: 2015-02-04T18:11:17.957Z
Answers.UserDisplayName: carlcs
Body: <p>I can grab a top/bottom level ancestor with something like entry.ancestors.first/last.title.</p>
  
  <p>But, say I'm at level 6, is it possible to grab an ancestor at a particular level, like entry.ancestors.level(3).title? Or would you have to grab all the ancestors and loop through them to accomplish this?</p>
  
  <p>New to deep structures and just want to confirm I'm not missing something that would allow me to sidestep a loop. Thanks!</p>
  
Tags: <structure>
Title: Get ancestor at a specific level?
ThreadText: # Get ancestor at a specific level?
  
  (Asked by: username_0 on 2015-02-04)
  
  I can grab a top/bottom level ancestor with something like entry.ancestors.first/last.title.
  
  But, say I'm at level 6, is it possible to grab an ancestor at a particular level, like entry.ancestors.level(3).title? Or would you have to grab all the ancestors and loop through them to accomplish this?
  
  New to deep structures and just want to confirm I'm not missing something that would allow me to sidestep a loop. Thanks!
  
  **Tags:** structure
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-02-04. Score: 3 | Accepted answer
  
  `entry.ancestors` returns an ElementCriteriaModel (→ [`getAncestors()`](http://buildwithcraft.com/docs/templating/entrymodel#getAncestors) in the Craft docs) prepped to return the entry's ancestors.
  
  `entry.ancestors.level(3)` makes it return only entry ancestors which are at 3rd level of the structure.
  
  As you well pointed out in the comments, an entry can only have one ancestor on a particular structure level. So you can now use the `first()` method to get this one entry. Keep in mind that if there's no ancestor at that level, the method won't return anything (`null`).
  
  ```
  {% set ancestorL3 = entry.ancestors.level(3).first() %}
  
  {% if ancestorL3 %}
      {{ ancestorL3.title }}
  {% endif %}
  
  ```
  
  > **Comments:**
  > **username_0**: I see… I was thinking .level(3) would return a single entry as .first does (not sure how an entry could have more than one ancestor at a particular level). Thanks!  
  > **username_1**: @alsophil male and female?? ...errrm no.  
  
  ---
  
  