Answers.Body: <p>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 <code>null</code></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-09T06:13:13.170Z
Answers.Text: Except that entry titles are being returned, just not `url` or `slug`.
Answers.UserDisplayName: Tyssen
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-09T06:14:22.423Z
Answers.Text: What do you do to display them? Only `{{ nextEntry }}`?
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-09T06:23:38.470Z
Answers.Text: If I do `{{ nextEntry }}` I get output like `Entry Title`. If I do `{{ nextEntry.url }}` or `{{ nextEntry.slug }}` I want to get `entry-title` but instead get the error.
Answers.UserDisplayName: Tyssen
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-09T06:25:50.070Z
Answers.Text: Because `{{ nextEntry }}` will trigger the objects `__toString` function. You don't actually access the real `title` attribute as with `{{ nextEntry.title }}`. Without that function you would receive an `object can not converted to string` Exception. You need to check if the variable is null or not. Short syntax would be `{{ nextEntry.url ?? '' }}`
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-09T06:33:10.520Z
Answers.Text: Sorry, you've lost me. If I do `{% set prevEntry = item.prev.slug %}` and check if `prevEntry` exists, I get the same type of error. If `item.prev` produces *something*, then surely the `slug` wouldn't be null because it's returning information about a valid entry that exists with a slug.
Answers.UserDisplayName: Tyssen
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-09T06:34:29.897Z
Answers.Text: In this case `item.prev` is null. `Impossible to access an attribute ("url") on a null variable.` is always the same kind of error.... you should google it, you'll receive plenty of recerences and all are solved in the very same way
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-09T05:53:25.330Z
Answers.LastActivityDate: 2018-07-09T05:53:25.330Z
Answers.UserDisplayName: Robin Schambach
Body: <p>I have a search results page set up like this:</p>
  
  <pre><code>{% 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 %}
  </code></pre>
  
  <p>That works fine except that it outputs the entry title of the next and previous entries. If I do <code>nextEntry.url</code> or <code>prevEntry.url</code> (or <code>slug</code>) I get:</p>
  
  <blockquote>
    <p>Impossible to access an attribute ("url") on a null variable.</p>
  </blockquote>
  
  <p>Why is that?</p>
  
Tags: <elementcriteriamodel><previous-next>
Title: Impossible to access an attribute ("url") on a null variable in search results
ThreadText: # Impossible to access an attribute ("url") on a null variable in search results
  
  (Asked by: username_0 on 2018-07-09)
  
  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?
  
  **Tags:** elementcriteriamodel, previous-next
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-07-09. Score: 1 | Accepted answer
  
  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`
  
  > **Comments:**
  > **username_0**: Except that entry titles are being returned, just not `url` or `slug`.  
  > **username_1**: What do you do to display them? Only `{{ nextEntry }}`?  
  > **username_0**: If I do `{{ nextEntry }}` I get output like `Entry Title`. If I do `{{ nextEntry.url }}` or `{{ nextEntry.slug }}` I want to get `entry-title` but instead get the error.  
  > **username_1**: Because `{{ nextEntry }}` will trigger the objects `__toString` function. You don't actually access the real `title` attribute as with `{{ nextEntry.title }}`. Without that function you would receive an `object can not converted to string` Exception. You need to check if the variable is null or not. Short syntax would be `{{ nextEntry.url ?? '' }}`  
  > **username_0**: Sorry, you've lost me. If I do `{% set prevEntry = item.prev.slug %}` and check if `prevEntry` exists, I get the same type of error. If `item.prev` produces *something*, then surely the `slug` wouldn't be null because it's returning information about a valid entry that exists with a slug.  
  > **username_1**: In this case `item.prev` is null. `Impossible to access an attribute ("url") on a null variable.` is always the same kind of error.... you should google it, you'll receive plenty of recerences and all are solved in the very same way  
  
  ---
  
  