Answers.Body: <p>Even if you set the limit to 1, Craft always returns an array of entries. So you need to add <code>first()</code> to access the first (and only) entry.</p>
  
  <pre><code>{{ entry.buttonTargets.first() }}
  </code></pre>
  
  <p>It you don't add a property, this returns the entry's title by default. So you additionally need to add <code>url</code> to output the URL of that entry.</p>
  
  <pre><code>{{ entry.buttonTargets.first().url }}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-06T17:24:27.683Z
Answers.Text: Thank you so much! This is exactly the hint I needed. I'm "new" to Craft, (love it) and didn't realize that regardless Craft will always return an array. Adding the additional property (url, id etc) makes perfect sense to get the value(s) I am after. Thank you!
Answers.UserDisplayName: Damon
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-06T17:28:28.033Z
Answers.Text: @dragonslovetacos a good thing to do is to always name the field handle in plurals for such fields: `buttonTargets` instead of `buttonTarget` for your Entries Field or `assets` for an Asset Field even if restricted to only take one asset.
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-06T17:34:34.877Z
Answers.Text: Great advice - will do!
Answers.UserDisplayName: Damon
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-06T20:12:59.037Z
Answers.Text: You should also check that that first entry exists:
  `{% if entry.buttonTargets.first() %}{{ entry.buttonTargets.first().url }}{% endif %}`
Answers.UserDisplayName: Marion Newlevant
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-03T12:16:29.603Z
Answers.Text: This worked, thank you! - SIDE NOTE - Just looked at the Docs and couldn't find a reference to the field type entry/entries returning an array - do you have a doc that clearly presents this to the user from the Craft documentation?
Answers.UserDisplayName: Wally
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-06T17:20:05.267Z
Answers.LastActivityDate: 2015-02-06T17:28:54.203Z
Answers.LastEditDate: 2015-02-06T17:28:54.203Z
Answers.UserDisplayName: carlcs
Body: <p>I am attempting to create a "dynamic" button. By that I mean I want the user to be able to update the text and the target (href) of where the button links to when clicked.</p>
  
  <p>So I created fields: <code>buttonText</code> and <code>buttonTarget</code>.</p>
  
  <p><code>buttonText</code> is just a plain text field - no problem.</p>
  
  <p>For the <code>buttonTarget</code> field type I chose "Entry" and selected the source(s) in the checklist that follows with a limit of one. So far so good.</p>
  
  <p>In my actual entry, I enter the <code>buttonText</code> of "Hello World". Preview the page and "Hello World" shows up as the button text. So far so good.</p>
  
  <p>Lets say I have a page called "Hello". For my <code>buttonTarget</code> field I click on "Add an Entry" and choose "Hello" from the entry list. </p>
  
  <p>When I preview my site now, I get this error:</p>
  
  <p><code>Object of class Craft\ElementCriteriaModel could not be converted to string</code></p>
  
  <p>That makes perfect sense since I need everything to evaluate to a string. I'm not sure how I can output (for lack of better words) the object so that I can see/find what properties are.</p>
  
  <p>Here is what I am using to display the button:</p>
  
  <p><strong>html</strong></p>
  
  <pre><code>&lt;p&gt;&lt;a href="{{entry.buttonTarget}}" class="btn btn-default"&gt;{{entry.buttonText}}&lt;/a&gt;&lt;/p&gt;
  </code></pre>
  
  <p>I assume I need something like <code>{{entry.buttonTarget.uri}}</code> but I haven't been able to find out what the actual parameter is I need. <code>{{entry.uri}}</code> outputs nothing.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Doing this gets the result I am after: <code>{{entry.slug}}</code> This uses the current entry's slug instead of the custom field value. Which is ok - I can use the slug as the href target. Ideally I'd like to use the custom field though.</p>
  
Tags: <templating><entry-type><fieldtypes>
Title: Link to an entry via Entries field type
ThreadText: # Link to an entry via Entries field type
  
  (Asked by: username_0 on 2015-02-06)
  
  I am attempting to create a "dynamic" button. By that I mean I want the user to be able to update the text and the target (href) of where the button links to when clicked.
  
  So I created fields: `buttonText` and `buttonTarget`.
  
  `buttonText` is just a plain text field - no problem.
  
  For the `buttonTarget` field type I chose "Entry" and selected the source(s) in the checklist that follows with a limit of one. So far so good.
  
  In my actual entry, I enter the `buttonText` of "Hello World". Preview the page and "Hello World" shows up as the button text. So far so good.
  
  Lets say I have a page called "Hello". For my `buttonTarget` field I click on "Add an Entry" and choose "Hello" from the entry list.
  
  When I preview my site now, I get this error:
  
  `Object of class Craft\ElementCriteriaModel could not be converted to string`
  
  That makes perfect sense since I need everything to evaluate to a string. I'm not sure how I can output (for lack of better words) the object so that I can see/find what properties are.
  
  Here is what I am using to display the button:
  
  **html**
  
  ```
  <p><a href="{{entry.buttonTarget}}" class="btn btn-default">{{entry.buttonText}}</a></p>
  
  ```
  
  I assume I need something like `{{entry.buttonTarget.uri}}` but I haven't been able to find out what the actual parameter is I need. `{{entry.uri}}` outputs nothing.
  
  **EDIT**
  
  Doing this gets the result I am after: `{{entry.slug}}` This uses the current entry's slug instead of the custom field value. Which is ok - I can use the slug as the href target. Ideally I'd like to use the custom field though.
  
  **Tags:** templating, entry-type, fieldtypes
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-02-06. Score: 14 | Accepted answer
  
  Even if you set the limit to 1, Craft always returns an array of entries. So you need to add `first()` to access the first (and only) entry.
  
  ```
  {{ entry.buttonTargets.first() }}
  
  ```
  
  It you don't add a property, this returns the entry's title by default. So you additionally need to add `url` to output the URL of that entry.
  
  ```
  {{ entry.buttonTargets.first().url }}
  
  ```
  
  > **Comments:**
  > **username_0**: Thank you so much! This is exactly the hint I needed. I'm "new" to Craft, (love it) and didn't realize that regardless Craft will always return an array. Adding the additional property (url, id etc) makes perfect sense to get the value(s) I am after. Thank you!  
  > **username_1**: @dragonslovetacos a good thing to do is to always name the field handle in plurals for such fields: `buttonTargets` instead of `buttonTarget` for your Entries Field or `assets` for an Asset Field even if restricted to only take one asset.  
  > **username_0**: Great advice - will do!  
  > **username_2**: You should also check that that first entry exists: `{% if entry.buttonTargets.first() %}{{ entry.buttonTargets.first().url }}{% endif %}`  
  > **username_3**: This worked, thank you! - SIDE NOTE - Just looked at the Docs and couldn't find a reference to the field type entry/entries returning an array - do you have a doc that clearly presents this to the user from the Craft documentation?  
  
  ---
  
  