How to get Structure parent title and ancestors on search results page I'm having trouble getting the Structure parent title on a search results page.

I followed these instructions 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') %}


&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;
Found the answer in getSection()

&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;