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 %}
<a href="{{ item.url }}
{% if nextEntry or prevEntry %}?{%endif%}
{% if nextEntry %}next={{nextEntry}}{%endif%}
{% if prevEntry and nextEntry %}&{% endif %}
{% if prevEntry %}prev={{prevEntry}}{%endif%}"
>Link</a>
{% 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?