<p>You said it yourself, the problem is that an Entries field can link to multiple targets. So it is an array of Entry Models you're given here, or more correctly, an ElementCriteriaModel.</p>

<p>To get the first linked entry's Url, all you have to change is to add the <code>first</code> method.</p>

<pre><code>&lt;a href="{{ imageItem.imageLink.first().url }}"&gt;
</code></pre>

<p>But you said multiple links are allowed, so to show them all go through them in a loop.</p>

<pre><code>{% for imageItem in block.images %}
    {% for linkedEntry in imageItem.imageLink %}
        &lt;a href="{{ linkedEntry.url }}"&gt;
            &lt;img src="{{ imageItem.url }}" alt=""&gt;
            &lt;span&gt;{{ imageItem.imageTitle }}&lt;/span&gt;
        &lt;/a&gt;
    {% endfor %}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2015-03-04T09:56:18.013Z
Perfect. This is my first Craft site and first time with Twig. I'm still finding my way around. Thanks.
Tim Print
CC BY-SA 3.0
2015-03-04T10:10:02.823Z
One more thing, @TimPrint. I'd recommend to always name an entries field handle in plural form, in you case it'd be `imageLinks` instead of `imageLink`. Entries fields always give you an ElementCriteriaModel and never a single Entry Model, even if you set the limit to 1 in the field settings. The same applies to asset fields, category fields, ...
carlcs
CC BY-SA 3.0
2015-05-05T15:25:02.140Z
Anything still not working for you, Tim?
carlcs
CC BY-SA 3.0
2015-05-06T18:54:28.293Z
Nope, all good, was just cleaning up some answers in here
Tim Print
CC BY-SA 3.0
2015-05-07T20:16:14.840Z
Sorry! I always forget you need to click that accept button. Done. Thanks again.
Tim Print
CC BY-SA 3.0
2015-03-04T05:59:25.640Z
2015-03-04T05:59:25.640Z
carlcs
<p>I have an Asset source "Image link gallery" with two custom fields for each Asset: "image title" (text field) &amp; "Image link" (Entries field - can link to multiple sources).</p>

<p>I have a Matrix block "Image link Gallery" with an Assets field "Images" which selects from this Asset source.</p>

<p>I want to be be able to select a bunch of images and return the image, title, and link to the entry.</p>

<pre><code>{% for imageItem in block.images %}
    &lt;a href="{{ imageItem.imageLink.uri }}"&gt;
        &lt;img src="{{ imageItem.url }}" alt=""&gt;
        &lt;span&gt;{{ imageItem.imageTitle }}&lt;/span&gt;
    &lt;/a&gt;
{% endfor %}
</code></pre>

<p>This is returning all the images and titles but no links.</p>

<p>Where am I going wrong?</p>

CC BY-SA 3.0
2015-03-04T04:49:05.453Z
In dev mode, what comes up with {{dump(imageItem.imageLink)}}?
Aaron Berkowitz
<assets><matrix><relations>
Asset with related entry field in Matrix block
# Asset with related entry field in Matrix block

(Asked by: username_0 on 2015-03-04)

I have an Asset source "Image link gallery" with two custom fields for each Asset: "image title" (text field) & "Image link" (Entries field - can link to multiple sources).
I have a Matrix block "Image link Gallery" with an Assets field "Images" which selects from this Asset source.
I want to be be able to select a bunch of images and return the image, title, and link to the entry.
{% for imageItem in block.images %}
    
        
        {{ imageItem.imageTitle }}
    
{% endfor %}

This is returning all the images and titles but no links.
Where am I going wrong?

**Tags:** assets, matrix, relations

> **Comments:**
> **username_1**: In dev mode, what comes up with {{dump(imageItem.imageLink)}}?  

---

## 1 answers

### Answer by username_2 on 2015-03-04. Score: 2 | Accepted answer

You said it yourself, the problem is that an Entries field can link to multiple targets. So it is an array of Entry Models you're given here, or more correctly, an ElementCriteriaModel.
To get the first linked entry's Url, all you have to change is to add the first method.


But you said multiple links are allowed, so to show them all go through them in a loop.
{% for imageItem in block.images %}
    {% for linkedEntry in imageItem.imageLink %}
        
            
            {{ imageItem.imageTitle }}
        
    {% endfor %}
{% endfor %}

> **Comments:**
> **username_0**: Perfect. This is my first Craft site and first time with Twig. I'm still finding my way around. Thanks.  
> **username_2**: One more thing, @TimPrint. I'd recommend to always name an entries field handle in plural form, in you case it'd be `imageLinks` instead of `imageLink`. Entries fields always give you an ElementCriteriaModel and never a single Entry Model, even if you set the limit to 1 in the field settings. The same applies to asset fields, category fields, ...  
> **username_2**: Anything still not working for you, Tim?  
> **username_0**: Nope, all good, was just cleaning up some answers in here  
> **username_0**: Sorry! I always forget you need to click that accept button. Done. Thanks again.  

---

