Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-10T02:04:22.407Z
Answers.Text: that didn't work. but dev mode is telling me it's this line- <div class="mainImage" style="background-image:url({{ asset.url }})"> </div>
Answers.UserDisplayName: user1949733
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-10T16:42:38.713Z
Answers.Text: 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 }}```.
Answers.UserDisplayName: Rob Erskine
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-10T01:21:31.353Z
Answers.LastActivityDate: 2015-11-10T01:21:31.353Z
Answers.UserDisplayName: Rob Erskine
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-10T03:04:17.570Z
Answers.Text: 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.
Answers.UserDisplayName: user1949733
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-10T03:17:35.023Z
Answers.Text: 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"
Answers.UserDisplayName: user1949733
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-10T04:39:52.960Z
Answers.Text: what is the name of your asset field? You'll access the asset via entry.<assetFieldName>
Answers.UserDisplayName: kcolls
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-10T15:06:21.490Z
Answers.Text: 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>
Answers.UserDisplayName: user1949733
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-10T15:30:45.253Z
Answers.Text: Try entry.mainImages.first.url
Answers.UserDisplayName: kcolls
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-10T02:57:00.033Z
Answers.LastActivityDate: 2015-11-10T15:39:05.797Z
Answers.LastEditDate: 2015-11-10T15:39:05.797Z
Answers.UserDisplayName: kcolls
Body: <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>
  
Tags: <templating><assets>
Title: Asset not appearing
ThreadText: # Asset not appearing
  
  (Asked by: username_0 on 2015-11-10)
  
  I am pulling assets from the work section like 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({{ asset.url }})"> </div>
              </a> 
    {% 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() %}
    <div class="mainImage" style="background-image:url({{ entry.asset.first().url }})"></div>
  {% 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  
  
  ---
  
  