Answers.Body: <p>Found the answer in <a href="https://craftcms.com/docs/templating/entrymodel#getSection" rel="nofollow noreferrer">getSection()</a></p>
  
  <pre><code>&lt;li&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;
  
    {% set section = entry.getSection() %}
     {{ section }}
    {% set parent1 = entry.getAncestors() %}
     {% for item in parent1 %}
      / {{ item }}
     {% endear %}
  
  &lt;/li&gt;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-06T16:58:49.237Z
Answers.LastActivityDate: 2016-12-06T17:08:23.613Z
Answers.LastEditDate: 2016-12-06T17:08:23.613Z
Answers.UserDisplayName: julzmon
Body: <p>I'm having trouble getting the Structure parent title on a search results page.</p>
  
  <p>I followed <a href="https://craftcms.stackexchange.com/questions/11614/title-of-the-current-parent-structure/11617#11617">these instructions</a> but I'm getting a "Impossible to access an attribute ("title") on a null variable" error.</p>
  
  <p>In the following code the all ancestors do print except the first level Structure title.</p>
  
  <pre><code>{% set query = craft.request.getParam('q') %}
  {# {% set entries = craft.entries.search(query).order('score') %} #}
  {% set entries = craft.entries.section().search(query).order('score') %}
  
  
  &lt;ul class="list-unstyled"&gt;
    {% for entry in entries %}
   &lt;li&gt;
    &lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;
    {% set parent1 = entry.getAncestors().level(1) %}
    {% for item in parent1 %}
        / {{ item.title }}
      {% endfor %}
    {% set parent2 = entry.getAncestors().level(2) %}
    {% for item in parent2 %}
        / {{ item.title }}
      {% endfor %}
    {% set parent3 = entry.getAncestors().level(3) %}
    {% for item in parent3 %}
      / {{ item.title }}
    {% endfor %}
   &lt;/li&gt;
    {% endfor %}
  &lt;ul&gt;
  </code></pre>
  
Tags: <structure><search>
Title: How to get Structure parent title and ancestors on search results page
ThreadText: # How to get Structure parent title and ancestors on search results page
  
  (Asked by: username_0 on 2016-12-06)
  
  I'm having trouble getting the Structure parent title on a search results page.
  
  I followed [these instructions](https://craftcms.stackexchange.com/questions/11614/title-of-the-current-parent-structure/11617#11617) but I'm getting a "Impossible to access an attribute ("title") on a null variable" error.
  
  In the following code the all ancestors do print except the first level Structure title.
  
  ```
  {% set query = craft.request.getParam('q') %}
  {# {% set entries = craft.entries.search(query).order('score') %} #}
  {% set entries = craft.entries.section().search(query).order('score') %}
  
  <ul class="list-unstyled">
    {% for entry in entries %}
   <li>
    <a href="{{ entry.url }}">{{ entry.title }}</a>
    {% set parent1 = entry.getAncestors().level(1) %}
    {% for item in parent1 %}
        / {{ item.title }}
      {% endfor %}
    {% set parent2 = entry.getAncestors().level(2) %}
    {% for item in parent2 %}
        / {{ item.title }}
      {% endfor %}
    {% set parent3 = entry.getAncestors().level(3) %}
    {% for item in parent3 %}
      / {{ item.title }}
    {% endfor %}
   </li>
    {% endfor %}
  <ul>
  
  ```
  
  **Tags:** structure, search
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2016-12-06. Score: 2
  
  Found the answer in [getSection()](https://craftcms.com/docs/templating/entrymodel#getSection)
  
  ```
  <li><a href="{{ entry.url }}">{{ entry.title }}</a>
  
    {% set section = entry.getSection() %}
     {{ section }}
    {% set parent1 = entry.getAncestors() %}
     {% for item in parent1 %}
      / {{ item }}
     {% endear %}
  
  </li>
  
  ```
  
  
  ---
  
  