Impossible to access an attribute ("url") on a null variable in search results I have a search results page set up like this:

{% set searchResults = craft.entries(queryParams) %}
{% paginate searchResults as pageInfo, pageEntries %}

{% if pageEntries|length %}
  {% for yacht in pageEntries %}
    {% set prevEntry = item.prev %}
    {% set nextEntry = item.next %}
    &lt;a href="{{ item.url }}
    {% if nextEntry or prevEntry %}?{%endif%}
    {% if nextEntry %}next={{nextEntry}}{%endif%}
    {% if prevEntry and nextEntry %}&amp;{% endif %}
    {% if prevEntry %}prev={{prevEntry}}{%endif%}"
    &gt;Link&lt;/a&gt;
  {% endfor %}
{% endif %}


That works fine except that it outputs the entry title of the next and previous entries. If I do nextEntry.url or prevEntry.url (or slug) I get:


  Impossible to access an attribute ("url") on a null variable.


Why is that?
You should check if there is a next and previous element. Most likely you reach the end or the beginning of your list and there is no element thus these variables are null so you receive an exception when you try to grab attributes from null