Answers.Body: <p>Ok, so I've managed to get an answer to this courtesy of Brandon Kelly.  It's much more simple than I thought.  Firstly, you do not have to specify a relatedTo parameter the defineCriteriaAttributes(). Craft takes care of this automatically.  So in order to retrieve the details of an asset in a table list view you do the following in the getTableAttributeHtml() function in your custom Element Type class:</p>
  
  <pre><code>$relatedAsset = $element-&gt;myAssetsField-&gt;first();
  </code></pre>
  
  <p>This simple line of code gets a related myAssetsField of your element. I'm not sure why, but this object is placed in an array...  Maybe someone can tell me why this is the case?</p>
  
  <p>I then took the fist element of the array and used a the getThumbUrl() function which is really handy for quickly outputting the url to a thumbnail.  I passed a size of 60 pixels.</p>
  
  <pre><code>case 'myAttribute&gt;':
  {   
     if(count($relatedAsset) &gt; 0) {
        return '&lt;img src="'.$relatedAsset[0]-&gt;getThumbUrl(60).'"&gt;';
     }
     return '';
  }
  </code></pre>
  
  <p>The result is a thumbnail in your table list!
  Hope this helps others....</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-22T16:35:59.250Z
Answers.Text: Nice to see this is that simple. Thanks for sharing, brasso!
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-22T16:29:23.123Z
Answers.LastActivityDate: 2015-01-22T16:29:23.123Z
Answers.UserDisplayName: brasso
Body: <p>Hi,</p>
  
  <p>I'm new to Craft and VERY new to plugin development.  I'd like to display a thumbnail image in my table list view and thought it would be possible to accomplish using a new Custom Element Type.  Does anybody know how to achieve this?</p>
  
  <p>I have managed to output custom fields in the table using defineTableAttributes() but I can't output any related Assets - in particular their filenames. Do I need to define a relation in the ElementCriteriaModel using the defineCriteriaAttributes() function?  Can anyone explain how this is done?</p>
  
  <p>Many thanks</p>
  
Tags: <plugin-development><elementcriteriamodel><elementtype><custom-field>
Title: Display thumbnail using defineTableAttributes for a custom Element Type
ThreadText: # Display thumbnail using defineTableAttributes for a custom Element Type
  
  (Asked by: username_0 on 2015-01-20)
  
  Hi,
  
  I'm new to Craft and VERY new to plugin development. I'd like to display a thumbnail image in my table list view and thought it would be possible to accomplish using a new Custom Element Type. Does anybody know how to achieve this?
  
  I have managed to output custom fields in the table using defineTableAttributes() but I can't output any related Assets - in particular their filenames. Do I need to define a relation in the ElementCriteriaModel using the defineCriteriaAttributes() function? Can anyone explain how this is done?
  
  Many thanks
  
  **Tags:** plugin-development, elementcriteriamodel, elementtype, custom-field
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2015-01-22. Score: 6
  
  Ok, so I've managed to get an answer to this courtesy of Brandon Kelly. It's much more simple than I thought. Firstly, you do not have to specify a relatedTo parameter the defineCriteriaAttributes(). Craft takes care of this automatically. So in order to retrieve the details of an asset in a table list view you do the following in the getTableAttributeHtml() function in your custom Element Type class:
  
  ```
  $relatedAsset = $element->myAssetsField->first();
  
  ```
  
  This simple line of code gets a related myAssetsField of your element. I'm not sure why, but this object is placed in an array... Maybe someone can tell me why this is the case?
  
  I then took the fist element of the array and used a the getThumbUrl() function which is really handy for quickly outputting the url to a thumbnail. I passed a size of 60 pixels.
  
  ```
  case 'myAttribute>':
  {   
     if(count($relatedAsset) > 0) {
        return '<img src="'.$relatedAsset[0]->getThumbUrl(60).'">';
     }
     return '';
  }
  
  ```
  
  The result is a thumbnail in your table list!
  Hope this helps others....
  
  > **Comments:**
  > **username_1**: Nice to see this is that simple. Thanks for sharing, username_0!  
  
  ---
  
  