<p>All related fields (assets, entries, categories, tags, etc) are designed to store more than one item, and thus always return an "array-like" object (although not technically an array), even if you have the limit set to 1. Thus you first need to either loop through the items or grab the first item using <code>first</code> or <code>[0]</code>. In addition, each item is an object model that has various object properties, that you will need to retrieve using dot syntax. So to get your url you would would want something like:</p>

<pre><code>{% for block in entry.homepageSlideshow %}
    &lt;a href="{{ block.slideLink.first.url }}"&gt;
    ...
{% endfor %}
</code></pre>

<p>or </p>

<pre><code>{% for block in entry.homepageSlideshow %}
    &lt;a href="{{ block.slideLink[0].url }}"&gt;
    ...
{% endfor %}
</code></pre>

CC BY-SA 3.0
2015-01-20T20:32:20.930Z
2015-01-20T20:32:20.930Z
Douglas McDonald
<p>You get this error because <code>{{ block.slideLink }}</code> returns an array of EntryModels (even if you set your Entries field up to only allow 1 entry). So you need to add the <code>first()</code> method to get the first (and only) EntryModel that you are interested in:</p>

<pre><code>{% set entry = block.slideLink.first() %}
</code></pre>

<p>Access the <code>url</code> property to return the URL of that entry:</p>

<pre><code>{% if entry %}
    {{ entry.url }}
{% endif %}
</code></pre>

CC BY-SA 3.0
2016-05-01T20:47:29.860Z
I had the same error when trying to access and asset for an entry. After adding the first() method everything worked as expected. Thanks @carlcs.
Justin K
CC BY-SA 3.0
2015-01-20T20:32:10.453Z
2017-06-30T23:28:51.640Z
2017-06-30T23:28:51.640Z
carlcs
<p>I'm trying to code up a Matrix field for a homepage slider, and it contains a single 'Slide' block type. It has fields for Image (Assets), Heading (Plain Text), Sub-Heading (Plain Text), and Slide Link (Entries). I've got everything working, except for the Slide Link field (where I want to output the entry URI for the entry that was selected in that field).</p>

<p>Whenever I add <code>{{ block.slideLink }}</code> to my template, I get the following error: </p>

<blockquote>
  <p>Object of class Craft\ElementCriteriaModel could not be converted to string</p>
</blockquote>

<p>So I'm obviously not meant to output a link to an entry (I only have one link being selected in the field) in this way, so can someone help me out with the syntax that I need please? There weren't any Entries examples in the <a href="http://buildwithcraft.com/docs/matrix-fields" rel="nofollow">Matrix Field docs</a> that I could copy from, and I couldn't figure out how to adapt the <a href="http://buildwithcraft.com/docs/entries-fields" rel="nofollow">Entries Field examples</a> to fit in with a Matrix field.</p>

<p>Thanks in advance for any help, and here's my code. The incorrect <code>{{ block.slideLink }}</code> code is on line 11:</p>

<pre><code>{% extends "_layout" %}

{% block content %}

  &lt;div class="grid-100 flexslider"&gt;
    &lt;ul class="slides"&gt;

      {% for block in entry.homepageSlideshow %}

        &lt;li&gt;
          &lt;a href="{{ block.slideLink }}"&gt;

            {% set largeImage = {
              mode: 'crop',
              width: 1180,
              height: 450,
              quality: 80
            } %}

            {% set image = block.image.first() %}
            {% if image %}
              &lt;img src="{{ image.getUrl(largeImage) }}" alt="{{ image.title }}"&gt;
            {% endif %}

            &lt;div class="flex-caption grid-40"&gt;
              &lt;h2&gt;{{ block.heading }}&lt;/h2&gt;
              &lt;p style="font-weight: bold;"&gt;{{ block.subHeading }}&lt;/p&gt;
            &lt;/div&gt;&lt;!-- flex-caption --&gt;

          &lt;/a&gt;
        &lt;/li&gt;
      {% endfor %}
    &lt;/ul&gt;
  &lt;/div&gt;&lt;!-- grid-100 --&gt;

{% endblock %}
</code></pre>

<templating><matrix><entries-field>
How to output an Entries Field value within a Matrix Field block
# How to output an Entries Field value within a Matrix Field block

(Asked by: username_0 on 2015-01-20)

I'm trying to code up a Matrix field for a homepage slider, and it contains a single 'Slide' block type. It has fields for Image (Assets), Heading (Plain Text), Sub-Heading (Plain Text), and Slide Link (Entries). I've got everything working, except for the Slide Link field (where I want to output the entry URI for the entry that was selected in that field).
Whenever I add {{ block.slideLink }} to my template, I get the following error: 

Object of class Craft\ElementCriteriaModel could not be converted to string

So I'm obviously not meant to output a link to an entry (I only have one link being selected in the field) in this way, so can someone help me out with the syntax that I need please? There weren't any Entries examples in the Matrix Field docs that I could copy from, and I couldn't figure out how to adapt the Entries Field examples to fit in with a Matrix field.
Thanks in advance for any help, and here's my code. The incorrect {{ block.slideLink }} code is on line 11:
{% extends "_layout" %}

{% block content %}

  
    

      {% for block in entry.homepageSlideshow %}

        
          

            {% set largeImage = {
              mode: 'crop',
              width: 1180,
              height: 450,
              quality: 80
            } %}

            {% set image = block.image.first() %}
            {% if image %}
              
            {% endif %}

            
              {{ block.heading }}
              {{ block.subHeading }}
            

          
        
      {% endfor %}
    
  

{% endblock %}

**Tags:** templating, matrix, entries-field

---

## 2 answers

### Answer by username_2 on 2015-01-20. Score: 13 | Accepted answer

You get this error because {{ block.slideLink }} returns an array of EntryModels (even if you set your Entries field up to only allow 1 entry). So you need to add the first() method to get the first (and only) EntryModel that you are interested in:
{% set entry = block.slideLink.first() %}

Access the url property to return the URL of that entry:
{% if entry %}
    {{ entry.url }}
{% endif %}

> **Comments:**
> **username_3**: I had the same error when trying to access and asset for an entry. After adding the first() method everything worked as expected. Thanks @carlcs.  

---

### Answer by username_1 on 2015-01-20. Score: 7

All related fields (assets, entries, categories, tags, etc) are designed to store more than one item, and thus always return an "array-like" object (although not technically an array), even if you have the limit set to 1. Thus you first need to either loop through the items or grab the first item using first or [0]. In addition, each item is an object model that has various object properties, that you will need to retrieve using dot syntax. So to get your url you would would want something like:
{% for block in entry.homepageSlideshow %}
    
    ...
{% endfor %}

or 
{% for block in entry.homepageSlideshow %}
    
    ...
{% endfor %}


---

