Add an assets field to a field type plugin template I have a plugin that creates custom field types to extend crafts default field types.

The custom field types hold several different form input fields. For example the field may be called video and contain a title field, caption field, video slug field and a thumbnail field.

When the plugin is installed these fields appear in the default field dropdown list.

I now want to change the html template in the plugin so that the thumbnail field makes use of the default assets field built into craft. So I'd like to know if there is a way to add an asset field to the twig template in my plugin. The plugin does not need to use it's own database so can make use of the existing assets database.

Is this possible?

This is what I have so far.

In the fieldtype class:

public function getInputHtml($name, $value)
{
    // If value is null, we set it to an array to prevent template errors
    if(!$value)
    {
      $value = array();
    }
    return craft()-&gt;templates-&gt;render('customfieldtypes/video', array(
        'name'  =&gt; $name,
        'value' =&gt; $value
    ));
}
public function prepValueFromPost($value)
{   
    return json_encode($value);
}

public function prepValue($value)
{
    return json_decode($value, TRUE);
}


In the video template:

&lt;label for="{{ name }}[title]"&gt;Title&lt;/label&gt;
&lt;input class="text nicetext fullwidth" type="text" name="{{ name }}[title]" value="{% if value %}{{ value.title }}{% else %}{{ null }}{% endif %}"&gt;&lt;br /&gt;
&lt;label for="{{ name }}[description]"&gt;Description&lt;/label&gt;
&lt;textarea class="text nicetext fullwidth" type="text" name="{{ name }}[description]"&gt;{% if value %}{{ value.description }}{% else %}{{ null }}{% endif %}&lt;/textarea&gt;&lt;br /&gt;
&lt;label for="{{ name }}[caption]"&gt;Caption&lt;/label&gt;
&lt;input class="text nicetext fullwidth" type="text" name="{{ name }}[caption]" value="{% if value %}{{ value.caption }}{% else %}{{ null }}{% endif %}"&gt;&lt;br /&gt;
&lt;label for="{{ name }}[link]"&gt;Link&lt;/label&gt;
&lt;input class="text nicetext fullwidth" type="text" name="{{ name }}[link]" value="{% if value %}{{ value.link }}{% else %}{{ null }}{% endif %}"&gt;&lt;br /&gt;
&lt;label for="{{ name }}[thumb]"&gt;Thumb&lt;/label&gt;
&lt;input class="text nicetext fullwidth" type="text" name="{{ name }}[thumb]" value="{% if value %}{{ value.thumb }}{% else %}{{ null }}{% endif %}"&gt;
I don't know enough about your end goal, but it almost sounds like what you're trying to do is what Craft already does very well. If you're just trying to save some time on Assets custom field creation, you might consider checking out FieldManager which lets you import/export fields across projects.