<p>You left off the <code>.first()</code>.</p>

<pre><code>{% set notFound = craft.entries.section('page404').first() %}
</code></pre>

<p>Without that, the Element Criteria Model will default to <code>.find()</code>.</p>

<ul>
<li><code>first</code> - Returns a single Entry Model.</li>
<li><code>find</code> - Returns an array of Entry Models.</li>
</ul>

<p><strong>It doesn't matter this this is a Single section!</strong> All Element Criteria Models have the same behavior, whether they're fetching data from a Single, Channel, or Structure.</p>

CC BY-SA 3.0
2016-09-14T20:53:01.937Z
Three items...   1) I no longer get an error.  And I can print the `body` field using `{{ notFound.body }}` ...but... 2) The image using `{{ notFound.postImage.first().url}}` does not display, even though it is assigned.   ...and 3) why is it possible to use `{{entry.title}} or `{{ entry.body}}` without defining `entry`  -- and here I am using the crafty brewery or default news channel in Craft.
Hellyar
CC BY-SA 3.0
2016-09-14T21:02:27.383Z
Do you have `devMode` enabled? I feel like some of these errors would be more apparent with that on.
Lindsey D
CC BY-SA 3.0
2016-09-14T23:05:21.190Z
Yes, and there is no error being thrown.
Hellyar
CC BY-SA 3.0
2016-09-14T23:21:53.417Z
Strange.  The thumb of the image appears in assets, with the correct file size.  It appears in the entry.  But it was not visible in assets when I tried to "view asset".  I was also unable to "replace file".   It said the file was "empty."  Anyway, I assume that is just a quirk. I deleted the asset and uploaded another copy.  Everything works now.  Many thanks.
Hellyar
CC BY-SA 3.0
2016-09-14T20:41:15.880Z
2016-09-14T20:41:15.880Z
Lindsey D
<p>I have the 404 page setup as a single in sections under <code>page404</code>.</p>

<p>I have a <code>postImage</code> field that pulls images from assets.  It is assigned to the <code>page404</code> field layout and it is assigned in the entry.  </p>

<p>I tried the this template approach:</p>

<pre><code>{% set notFound = craft.entries.section('page404') %}
&lt;img src="{{ notFound.postImage.first().url }}" width="800" height="800" alt=""&gt;
</code></pre>

<p>but I keep getting the following error:</p>

<blockquote>
  <p>Impossible to access an attribute ("url") on a null variable</p>
</blockquote>

<p><strong><em>What am I doing wrong, and how should it be template?</em></strong></p>

<templating><singles>
Can't Access Image URL on Single Page
# Can't Access Image URL on Single Page

(Asked by: username_0 on 2016-09-14)

I have the 404 page setup as a single in sections under page404.
I have a postImage field that pulls images from assets.  It is assigned to the page404 field layout and it is assigned in the entry.  
I tried the this template approach:
{% set notFound = craft.entries.section('page404') %}


but I keep getting the following error:

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

What am I doing wrong, and how should it be template?

**Tags:** templating, singles

---

## 1 answers

### Answer by username_1 on 2016-09-14. Score: 1 | Accepted answer

You left off the .first().
{% set notFound = craft.entries.section('page404').first() %}

Without that, the Element Criteria Model will default to .find().

first - Returns a single Entry Model.
find - Returns an array of Entry Models.

It doesn't matter this this is a Single section! All Element Criteria Models have the same behavior, whether they're fetching data from a Single, Channel, or Structure.

> **Comments:**
> **username_0**: Three items...   1) I no longer get an error.  And I can print the `body` field using `{{ notFound.body }}` ...but... 2) The image using `{{ notFound.postImage.first().url}}` does not display, even though it is assigned.   ...and 3) why is it possible to use `{{entry.title}} or `{{ entry.body}}` without defining `entry`  -- and here I am using the crafty brewery or default news channel in Craft.  
> **username_1**: Do you have `devMode` enabled? I feel like some of these errors would be more apparent with that on.  
> **username_0**: Yes, and there is no error being thrown.  
> **username_0**: Strange.  The thumb of the image appears in assets, with the correct file size.  It appears in the entry.  But it was not visible in assets when I tried to "view asset".  I was also unable to "replace file".   It said the file was "empty."  Anyway, I assume that is just a quirk. I deleted the asset and uploaded another copy.  Everything works now.  Many thanks.  

---

