<p>Make sure you know the asset exists first:</p>

<pre><code>{% if entry.asset.first() %}
  &lt;div class="mainImage" style="background-image:url({{ entry.asset.first().url }})"&gt;&lt;/div&gt;
{% endif %}
</code></pre>

<p>Another nifty trick is to enable "dev mode". This will give you detailed stack traces about what's going wrong in your instance! </p>

<p><a href="http://buildwithcraft.com/docs/config-settings#devMode" rel="nofollow">http://buildwithcraft.com/docs/config-settings#devMode</a></p>

CC BY-SA 3.0
2015-11-10T02:04:22.407Z
that didn't work. but dev mode is telling me it's this line- <div class="mainImage" style="background-image:url({{ asset.url }})"> </div>
user1949733
CC BY-SA 3.0
2015-11-10T16:42:38.713Z
Is `asset` the fieldname you've used? It should be attached to the `entry` object as well. So it should look like ```{{ entry.yourCustomFieldname.first().url }}```.
Rob Erskine
CC BY-SA 3.0
2015-11-10T01:21:31.353Z
2015-11-10T01:21:31.353Z
Rob Erskine
<p>Your issue is that you are calling <code>asset.url</code> rather than <code>entry.asset.first.url</code>. The variable 'asset' does not exist. The asset is a field of the entry, and must be referenced as such.</p>

<p>Edit: I assumed your field name was called 'asset'. You should be calling entry.assetFieldHandle.first.url.</p>

CC BY-SA 3.0
2015-11-10T03:04:17.570Z
Are you saying that I should have this - <div class="mainImage" style="background-image:url({{ entry.asset.first.url }})"> </div> because that doesn't work. I had this working perfectly before, I can't figure out what has gone wrong.
user1949733
CC BY-SA 3.0
2015-11-10T03:17:35.023Z
So, the variable asset doesn't exist. But if I replace asset.url with entry.asset.first.url, I get 'do not have a method or closure named "asset"
user1949733
CC BY-SA 3.0
2015-11-10T04:39:52.960Z
what is the name of your asset field? You'll access the asset via entry.<assetFieldName>
kcolls
CC BY-SA 3.0
2015-11-10T15:06:21.490Z
So it should be this?   <div class="header_image">
      {% for entry in craft.entries.section('work').limit(5) %}
                <a href="{{ entry.url }}">  
                <div class="mainImage" style="background-image:url({{ entry.asset('mainImages').url }} )"> </div>
                </a>      
      {% endfor %}
    </div>
user1949733
CC BY-SA 3.0
2015-11-10T15:30:45.253Z
Try entry.mainImages.first.url
kcolls
CC BY-SA 3.0
2015-11-10T02:57:00.033Z
2015-11-10T15:39:05.797Z
2015-11-10T15:39:05.797Z
kcolls
<p>I am pulling assets from the work section like this-</p>

<pre><code>&lt;div class="header_image"&gt;
  {% for entry in craft.entries.section('work').limit(5) %}
            &lt;a href="{{ entry.url }}"&gt;  
            &lt;div class="mainImage" style="background-image:url({{ asset.url }})"&gt; &lt;/div&gt;
            &lt;/a&gt; 
  {% endfor %}
</code></pre>

<p>     </p>

<p>The Asset isn't appearing on the page but if I hover over where the image should, the link is working properly and I can to get that entry. The asset.url isn't working and I'm not sure what else it should be. Any ideas? </p>

<templating><assets>
Asset not appearing
# Asset not appearing

(Asked by: username_0 on 2015-11-10)

I am pulling assets from the work section like this-

  {% for entry in craft.entries.section('work').limit(5) %}
              
             
             
  {% endfor %}

 
The Asset isn't appearing on the page but if I hover over where the image should, the link is working properly and I can to get that entry. The asset.url isn't working and I'm not sure what else it should be. Any ideas?

**Tags:** templating, assets

---

## 2 answers

### Answer by username_1 on 2015-11-10. Score: 2

Make sure you know the asset exists first:
{% if entry.asset.first() %}
  
{% endif %}

Another nifty trick is to enable "dev mode". This will give you detailed stack traces about what's going wrong in your instance! 
http://buildwithcraft.com/docs/config-settings#devMode

> **Comments:**
> **username_0**: that didn't work. but dev mode is telling me it's this line- <div class="mainImage" style="background-image:url({{ asset.url }})"> </div>  
> **username_1**: Is `asset` the fieldname you've used? It should be attached to the `entry` object as well. So it should look like ```{{ entry.yourCustomFieldname.first().url }}```.  

---

### Answer by username_2 on 2015-11-10. Score: 1

Your issue is that you are calling `asset.url` rather than `entry.asset.first.url`. The variable 'asset' does not exist. The asset is a field of the entry, and must be referenced as such.

Edit: I assumed your field name was called 'asset'. You should be calling entry.assetFieldHandle.first.url.

> **Comments:**
> **username_0**: Are you saying that I should have this - <div class="mainImage" style="background-image:url({{ entry.asset.first.url }})"> </div> because that doesn't work. I had this working perfectly before, I can't figure out what has gone wrong.  
> **username_0**: So, the variable asset doesn't exist. But if I replace asset.url with entry.asset.first.url, I get 'do not have a method or closure named "asset"  
> **username_2**: what is the name of your asset field? You'll access the asset via entry.<assetFieldName>  
> **username_0**: So it should be this?   <div class="header_image">       {% for entry in craft.entries.section('work').limit(5) %}                 <a href="{{ entry.url }}">                   <div class="mainImage" style="background-image:url({{ entry.asset('mainImages').url }} )"> </div>                 </a>             {% endfor %}     </div>  
> **username_2**: Try entry.mainImages.first.url  

---

