<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>

CC BY-SA 3.0
2015-01-22T16:35:59.250Z
Nice to see this is that simple. Thanks for sharing, brasso!
carlcs
CC BY-SA 3.0
2015-01-22T16:29:23.123Z
2015-01-22T16:29:23.123Z
brasso
<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>

<plugin-development><elementcriteriamodel><elementtype><custom-field>
Display thumbnail using defineTableAttributes for a custom Element Type
# 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 '';
   }
   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, brasso!  

---

