<p>Yes - you can access it exactly the same way you do in the templates; you just need to use PHP syntax (e.g. <code>-&gt;</code> for accessing sub-properties rather than <code>.</code>).</p>

<pre class="lang-php prettyprint-override"><code>'transformer' =&gt; function(EntryModel $entry) {
    // Begin defining the response data for this entry
    $data = [
        'excerpt' =&gt; $entry-&gt;excerpt,
    ];

    // Get the first asset in a "heroImage" Assets field (if there is one)
    $heroImage = $entry-&gt;heroImage-&gt;first();

    if ($heroImage) {
        $data['heroImage'] = $heroImage-&gt;url;
    }

    return $data;
})
</code></pre>

CC BY-SA 3.0
2016-01-14T22:19:52.153Z
Hi Brandon, works a charm. Thanks, and thanks for the stellar software!
A Ron
CC BY-SA 3.0
2016-01-14T21:26:58.743Z
2016-01-14T21:26:58.743Z
Brandon Kelly
<p>I'm using the Element API plugin to return data from an entry that also contains an image asset. Is there a way to combine the two so I can get the asset URL alongside the entry fields? </p>

<p>Attached below is an approximation of my line of thinking.</p>

<pre><code>        'elementType' =&gt; 'Entry',
        'criteria' =&gt; ['section' =&gt; 'wax'],

        'transformer' =&gt; function(EntryModel $entry) {
            return [
                'excerpt' =&gt; $entry-&gt;excerpt,
                'heroImage' =&gt; $asset-&gt;heroImage.url // Something like this?
            ];
</code></pre>

CC BY-SA 3.0
2016-01-14T21:23:34.207Z
So the asset field is a custom field on the entry?
Brad Bell
<elementcriteriamodel><plugin-elementapi>
Is there a way to return asset data along with entry data?
# Is there a way to return asset data along with entry data?

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

I'm using the Element API plugin to return data from an entry that also contains an image asset. Is there a way to combine the two so I can get the asset URL alongside the entry fields? 
Attached below is an approximation of my line of thinking.
        'elementType' => 'Entry',
        'criteria' => ['section' => 'wax'],

        'transformer' => function(EntryModel $entry) {
            return [
                'excerpt' => $entry->excerpt,
                'heroImage' => $asset->heroImage.url // Something like this?
            ];

**Tags:** elementcriteriamodel, plugin-elementapi

> **Comments:**
> **username_1**: So the asset field is a custom field on the entry?  

---

## 1 answers

### Answer by username_2 on 2016-01-14. Score: 4

Yes - you can access it exactly the same way you do in the templates; you just need to use PHP syntax (e.g. -> for accessing sub-properties rather than .).
'transformer' => function(EntryModel $entry) {
    // Begin defining the response data for this entry
    $data = [
        'excerpt' => $entry->excerpt,
    ];

    // Get the first asset in a "heroImage" Assets field (if there is one)
    $heroImage = $entry->heroImage->first();

    if ($heroImage) {
        $data['heroImage'] = $heroImage->url;
    }

    return $data;
})

> **Comments:**
> **username_0**: Hi Brandon, works a charm. Thanks, and thanks for the stellar software!  

---

