Answers.Body: <p>You'll need to use the <code>find</code> method rather than <code>first</code> and <code>last</code>, in order to pull all the entries.</p>
  
  <p>Then, you'll have to <em>loop through the entries</em>, appending their titles to a variable which will be used for the attribute's HTML value in the list view.</p>
  
  <p>Here, I'm pushing the entry titles to an array called <code>$tempArray</code>. After looping, the array is joined and returned as a comma separated list:</p>
  
  <pre><code>public function getEntryTableAttributeHtml(EntryModel $entry, $attribute)
  {
      if ($attribute == 'sponsorEntries')
      {
          if ($sponsorEntries = @$entry-&gt;$attribute-&gt;find())
          {
              $tempArray = [];
              foreach ($sponsorEntries as $sponsorEntry)
              {
                  $tempArray[] = $sponsorEntry-&gt;title;
              }
              // Will return "Awesome Entry, Another Awesome Entry"
              return implode(', ', $tempArray);
          }
      }
  }
  </code></pre>
  
  <p>If you want to, you can also make the entry titles in the list view clickable – i.e., to make it easy for your content editor to edit those entries – by wrapping the titles in anchor tags and pulling the entries' <code>cpEditUrl</code> property:</p>
  
  <pre><code>if ($sponsorEntries = @$entry-&gt;$attribute-&gt;find())
  {
      $tempArray = [];
      foreach ($sponsorEntries as $sponsorEntry)
      {
          $tempArray[] = '&lt;a href="' . $sponsorEntry-&gt;cpEditUrl . '"&gt;' . $sponsorEntry-&gt;title . '&lt;/a&gt;';
      }
      return implode(', ', $tempArray);
   }
  </code></pre>
  
  <p>...or if you prefer, you can make the links point to the entries on the frontend, by using <code>$sponsorEntry-&gt;url</code> instead:</p>
  
  <pre><code>$tempArray[] = '&lt;a href="' . $sponsorEntry-&gt;url . '" target="_blank"&gt;' . $sponsorEntry-&gt;title . '&lt;/a&gt;';
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-30T21:19:13.643Z
Answers.Text: Thanks for this, when adding this to getEntryTableAttributeHtml and reloading the entries, I get a blank list (nothing renders), do I have to update `modifyEntryTableAttributes` too? Right now I just have `$attributes['sponsorEntries'] = Craft::t('Sponsor(s)');`
Answers.UserDisplayName: Kenyon Kowal
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-30T21:19:55.917Z
Answers.Text: Nope, looks good :)
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-30T21:25:42.507Z
Answers.Text: hm, I can't seem to get it working. The list page goes blank when adding either of the code samples.
Answers.UserDisplayName: Kenyon Kowal
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-30T21:28:33.933Z
Answers.Text: I tested it and the code runs fine on my end. If the page goes blank its a PHP error; turn on dev mode and you'll likely see an error message. Also check logs under /craft/storage/runtime/logs
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-30T21:31:03.463Z
Answers.Text: Well actually I just spotted a typo in my example – had ```$element``` in place of ```$entry``` in a couple of spots. Edited the answer; should be correct now. Sorry about that – test again and see if the error goes away.
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-30T21:43:53.477Z
Answers.Text: Sorry about this, but nope, it's now giving me a `An unknown error occurred.` but if I remove it and revert back into my old code `if ($attribute == 'sponsorEntries'){ $cat = $entry->sponsorEntries->first(); return '<span>'.$cat.'</span>';}` it starts working again.
Answers.UserDisplayName: Kenyon Kowal
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-30T21:50:54.613Z
Answers.Text: Did you check your logs? Might be a more helpful error message in there.
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-30T21:51:40.397Z
Answers.Text: Ya when I switch `@$element` to `@$entry` it gives me `An unknown error occurred.` I'm in dev mode and I'm not getting any error logs
Answers.UserDisplayName: Kenyon Kowal
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-30T21:58:25.350Z
Answers.Text: Okay, what you can do, is to fire up Dev Tools in your browser of choice and refresh the page. When the AJAX call to ```getElements``` fails, you should see it in the Network pane. Click it, and you might see the original CException error and stack trace ([its going to look something like this](http://cly.mmikkel.no/image/0Y140l141G1J)).
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-30T22:15:50.143Z
Answers.Text: Hey, yep got this, http://grab.by/KPwq     http://grab.by/KPwK
Answers.UserDisplayName: Kenyon Kowal
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-30T23:26:22.037Z
Answers.Text: @knynkwl can you share the full stack trace of the error past `#0` and `#1`?
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-01T00:05:52.670Z
Answers.Text: @knynkwl Right, that doesn't appear to be an error within the ```getEntryTableAttributeHtml``` code, per se – looks like a separate issue. It's weird that it doesn't occur when you use ```first``` and ```last``` over ```find``` though... its possibly isolated to one or several entries inbetween the first and last one?
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-01T01:29:07.750Z
Answers.Text: @BradBell there is two links in my comment above with the full stack error. but here it is again.  http://grab.by/KPwq thanks
Answers.UserDisplayName: Kenyon Kowal
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-01T01:32:58.493Z
Answers.Text: @mmikkel Is it possible that we have to test if there is at least one entry available before running your code? Some entries are not assigned a Sponsor Entry.
Answers.UserDisplayName: Kenyon Kowal
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-01T01:36:25.230Z
Answers.Text: Not really, thats what the @ is there for. It suppresses errors if the attribute isn't found on the entry. And if it's there, but empty, the implode statement will just return an empty string.
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-01T01:37:22.243Z
Answers.Text: Ah, makes sense. damn haha
Answers.UserDisplayName: Kenyon Kowal
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-19T01:35:32.477Z
Answers.Text: Coming back to this, It seemed to work. Must have been a cache issue or something. Thanks again @mmikkel!
Answers.UserDisplayName: Kenyon Kowal
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-30T19:21:47.020Z
Answers.LastActivityDate: 2015-09-30T21:29:48.043Z
Answers.LastEditDate: 2015-09-30T21:29:48.043Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Body: <p>I am trying to return an array of selected entries in the list view, but so far I can only get <code>first()</code> and <code>last()</code> to export the names, since it's only grabbing one entry. I would like to get a comma separated list of entries tied the that specific entry.</p>
  
  <p>I have tried using <code>find()</code> and <code>find()-&gt;title</code> but it gives me an error.</p>
  
  <p>Here's what I have right now.</p>
  
  <pre><code>    public function getEntryTableAttributeHtml(EntryModel $entry, $attribute){
       if ($attribute == 'sponsorEntries'){
        return '&lt;span&gt;'.$entry-&gt;sponsorEntries-&gt;first().'&lt;/span&gt;';
       }
      }
  </code></pre>
  
  <p>and then I call it:</p>
  
  <pre><code>        // Artists
       public function modifyEntryTableAttributes(&amp;$attributes, $source){
        if ($source == 'section:9'){
          $attributes['sponsorEntries'] = Craft::t('Sponsor');
        }
       }
  </code></pre>
  
  <p>but I would like to get return all the entries, not just the first() one like the screenshot below illustrates.</p>
  
  <p><a href="https://i.sstatic.net/iUGqp.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/iUGqp.png" alt="enter image description here"></a></p>
  
Tags: <entries><plugins>
Title: Export Array of entries in modifyEntryTableAttributes
ThreadText: # Export Array of entries in modifyEntryTableAttributes
  
  (Asked by: username_0 on 2015-09-30)
  
  I am trying to return an array of selected entries in the list view, but so far I can only get `first()` and `last()` to export the names, since it's only grabbing one entry. I would like to get a comma separated list of entries tied the that specific entry.
  
  I have tried using `find()` and `find()->title` but it gives me an error.
  
  Here's what I have right now.
  
  ```
      public function getEntryTableAttributeHtml(EntryModel $entry, $attribute){
       if ($attribute == 'sponsorEntries'){
        return '<span>'.$entry->sponsorEntries->first().'</span>';
       }
      }
  
  ```
  
  and then I call it:
  
  ```
          // Artists
       public function modifyEntryTableAttributes(&$attributes, $source){
        if ($source == 'section:9'){
          $attributes['sponsorEntries'] = Craft::t('Sponsor');
        }
       }
  
  ```
  
  but I would like to get return all the entries, not just the first() one like the screenshot below illustrates.
  
  [![enter image description here](https://i.sstatic.net/iUGqp.png)](https://i.sstatic.net/iUGqp.png)
  
  **Tags:** entries, plugins
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-09-30. Score: 3 | Accepted answer
  
  You'll need to use the `find` method rather than `first` and `last`, in order to pull all the entries.
  
  Then, you'll have to *loop through the entries*, appending their titles to a variable which will be used for the attribute's HTML value in the list view.
  
  Here, I'm pushing the entry titles to an array called `$tempArray`. After looping, the array is joined and returned as a comma separated list:
  
  ```
  public function getEntryTableAttributeHtml(EntryModel $entry, $attribute)
  {
      if ($attribute == 'sponsorEntries')
      {
          if ($sponsorEntries = @$entry->$attribute->find())
          {
              $tempArray = [];
              foreach ($sponsorEntries as $sponsorEntry)
              {
                  $tempArray[] = $sponsorEntry->title;
              }
              // Will return "Awesome Entry, Another Awesome Entry"
              return implode(', ', $tempArray);
          }
      }
  }
  
  ```
  
  If you want to, you can also make the entry titles in the list view clickable – i.e., to make it easy for your content editor to edit those entries – by wrapping the titles in anchor tags and pulling the entries' `cpEditUrl` property:
  
  ```
  if ($sponsorEntries = @$entry->$attribute->find())
  {
      $tempArray = [];
      foreach ($sponsorEntries as $sponsorEntry)
      {
          $tempArray[] = '<a href="' . $sponsorEntry->cpEditUrl . '">' . $sponsorEntry->title . '</a>';
      }
      return implode(', ', $tempArray);
   }
  
  ```
  
  ...or if you prefer, you can make the links point to the entries on the frontend, by using `$sponsorEntry->url` instead:
  
  ```
  $tempArray[] = '<a href="' . $sponsorEntry->url . '" target="_blank">' . $sponsorEntry->title . '</a>';
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks for this, when adding this to getEntryTableAttributeHtml and reloading the entries, I get a blank list (nothing renders), do I have to update `modifyEntryTableAttributes` too? Right now I just have `$attributes['sponsorEntries'] = Craft::t('Sponsor(s)');`  
  > **username_1**: Nope, looks good :)  
  > **username_0**: hm, I can't seem to get it working. The list page goes blank when adding either of the code samples.  
  > **username_1**: I tested it and the code runs fine on my end. If the page goes blank its a PHP error; turn on dev mode and you'll likely see an error message. Also check logs under /craft/storage/runtime/logs  
  > **username_1**: Well actually I just spotted a typo in my example – had ```$element``` in place of ```$entry``` in a couple of spots. Edited the answer; should be correct now. Sorry about that – test again and see if the error goes away.  
  > **username_0**: Sorry about this, but nope, it's now giving me a `An unknown error occurred.` but if I remove it and revert back into my old code `if ($attribute == 'sponsorEntries'){ $cat = $entry->sponsorEntries->first(); return '<span>'.$cat.'</span>';}` it starts working again.  
  > **username_1**: Did you check your logs? Might be a more helpful error message in there.  
  > **username_0**: Ya when I switch `@$element` to `@$entry` it gives me `An unknown error occurred.` I'm in dev mode and I'm not getting any error logs  
  > **username_1**: Okay, what you can do, is to fire up Dev Tools in your browser of choice and refresh the page. When the AJAX call to ```getElements``` fails, you should see it in the Network pane. Click it, and you might see the original CException error and stack trace ([its going to look something like this](http://cly.mmikkel.no/image/0Y140l141G1J)).  
  > **username_0**: Hey, yep got this, http://grab.by/KPwq     http://grab.by/KPwK  
  > **username_2**: @knynkwl can you share the full stack trace of the error past `#0` and `#1`?  
  > **username_1**: @knynkwl Right, that doesn't appear to be an error within the ```getEntryTableAttributeHtml``` code, per se – looks like a separate issue. It's weird that it doesn't occur when you use ```first``` and ```last``` over ```find``` though... its possibly isolated to one or several entries inbetween the first and last one?  
  > **username_0**: @username_2 there is two links in my comment above with the full stack error. but here it is again.  http://grab.by/KPwq thanks  
  > **username_0**: @mmikkel Is it possible that we have to test if there is at least one entry available before running your code? Some entries are not assigned a Sponsor Entry.  
  > **username_1**: Not really, thats what the @ is there for. It suppresses errors if the attribute isn't found on the entry. And if it's there, but empty, the implode statement will just return an empty string.  
  > **username_0**: Ah, makes sense. damn haha  
  > **username_0**: Coming back to this, It seemed to work. Must have been a cache issue or something. Thanks again @mmikkel!  
  
  ---
  
  