Answers.Body: <p><code>property.imageBackground</code> is an <a href="http://buildwithcraft.com/docs/templating/elementcriteriamodel" rel="nofollow">ElementCriteriaModel</a>, which is to say that it always behaves much like an array of assets (even if you are sure there is only one).</p>
  
  <p>So the short answer is that you need:</p>
  
  <pre><code>style="background-image: url({{ property.imageBackground.first.url }});"
  </code></pre>
  
  <p>The catch here is that this will fail if there is for some reason no such asset. This can happen even if the field is required, and so you should always check. There are several ways to check. This is straightforward:</p>
  
  <pre><code>{% if property.imageBackground|length %}
    {{ property.imageBackground.first.url }}
  {% endif %}
  </code></pre>
  
  <p>Or you can use a loop:</p>
  
  <pre><code>{% for background in property.imageBackground %}
    {{ background.url }}
  {% endfor %}
  </code></pre>
  
  <p>Or a default (this uses twig's <a href="http://twig.sensiolabs.org/doc/templates.html#other-operators" rel="nofollow">?:</a> operator, and relies on some global image always being there, but you now only have one image to make certain is <strong>always</strong> there):</p>
  
  <pre><code>{% set background = property.imageBackground.first
     ?: g_config.defaultBackgroundImage.first
  %}
  {{ background.url }}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-31T20:57:07.483Z
Answers.LastActivityDate: 2015-08-31T20:57:07.483Z
Answers.UserDisplayName: Marion Newlevant
Body: <p>I have a structure, holding areas (level 1), and properties (level 2). I use entry types to pick what template will be used.</p>
  
  <p>In my entry type 'area' template I'm listing the children of 'area' ('properties'). 
  The children (entry type 'property', has an image field that I want to pull into my area template.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>{% set properties = entry.getChildren() %}
  {% if properties | length %}
  &lt;div class="container"&gt;
    &lt;h2&gt;Properties&lt;/h2&gt;
  
    &lt;div class="row"&gt;
      {% for property in properties %}
      &lt;div class="col-md-6 col-lg-4"&gt;
        &lt;a href="{{property.url}}"&gt;
          &lt;div class="module" style="background-image: url('???');"&gt;
            &lt;span&gt;
              &lt;h2&gt;{{property.title}}&lt;/h2&gt;
            &lt;/span&gt;
          &lt;/div&gt;
        &lt;/a&gt;
      &lt;/div&gt;
      {% endfor %}
    &lt;/div&gt;
  
  &lt;/div&gt;
  {% endif %}
  </code></pre>
  
  <p>This works, except I can't figure out how to pull the imageurl from the asset 'imageBackground' that sits in the entry type 'property' field layout. </p>
  
  <p>Anyone?</p>
  
Tags: <assets>
Title: How do I pull an image from a child entry of a structure
ThreadText: # How do I pull an image from a child entry of a structure
  
  (Asked by: username_0 on 2015-08-31)
  
  I have a structure, holding areas (level 1), and properties (level 2). I use entry types to pick what template will be used.
  
  In my entry type 'area' template I'm listing the children of 'area' ('properties').
  The children (entry type 'property', has an image field that I want to pull into my area template.
  
  Here's the code:
  
  ```
  {% set properties = entry.getChildren() %}
  {% if properties | length %}
  <div class="container">
    <h2>Properties</h2>
  
    <div class="row">
      {% for property in properties %}
      <div class="col-md-6 col-lg-4">
        <a href="{{property.url}}">
          <div class="module" style="background-image: url('???');">
            <span>
              <h2>{{property.title}}</h2>
            </span>
          </div>
        </a>
      </div>
      {% endfor %}
    </div>
  
  </div>
  {% endif %}
  
  ```
  
  This works, except I can't figure out how to pull the imageurl from the asset 'imageBackground' that sits in the entry type 'property' field layout.
  
  Anyone?
  
  **Tags:** assets
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-08-31. Score: 2
  
  `property.imageBackground` is an [ElementCriteriaModel](http://buildwithcraft.com/docs/templating/elementcriteriamodel), which is to say that it always behaves much like an array of assets (even if you are sure there is only one).
  
  So the short answer is that you need:
  
  ```
  style="background-image: url({{ property.imageBackground.first.url }});"
  
  ```
  
  The catch here is that this will fail if there is for some reason no such asset. This can happen even if the field is required, and so you should always check. There are several ways to check. This is straightforward:
  
  ```
  {% if property.imageBackground|length %}
    {{ property.imageBackground.first.url }}
  {% endif %}
  
  ```
  
  Or you can use a loop:
  
  ```
  {% for background in property.imageBackground %}
    {{ background.url }}
  {% endfor %}
  
  ```
  
  Or a default (this uses twig's [?:](http://twig.sensiolabs.org/doc/templates.html#other-operators) operator, and relies on some global image always being there, but you now only have one image to make certain is **always** there):
  
  ```
  {% set background = property.imageBackground.first
     ?: g_config.defaultBackgroundImage.first
  %}
  {{ background.url }}
  
  ```
  
  
  ---
  
  