I've created an Asset Source and assigned my own field via the field layout.
Then, I created an Assets Field to display a single image on a page. Using my plugins twig extension I can query the image object like so:
{{ entry.featuredImage.first()|myTwigExt }}
Now, in the Twig extension I want to target the first instance of my field using its Type, not the Handle.
The reason for this is because the handle can be defined by the user, but the type name is always the same. I want to avoid the need to parse in the field handle along with the Twig Extension like this:
{{ entry.featuredImage.first()|myTwigExt('notThis') }}
If this is even possible, my ideal situation would have my Twig Extension looking something like this:
public function getFilters() {
return array(
'myTwigExt' => new Twig_Filter_Method($this, 'myTwigExtension'),
);
}
public function myTwigExtension($image, $param) {
if ( $image->type('myCustomField') ) {
// YAY!
return $image->type('myCustomField')->someDataFromMyField;
}
if ( $image->$param ) {
// "Boo!";
return $image->$param->someDataFromMyField;
}
}
This is the cleanest way I can ask this question. Without going into too much detail about my plugin (which would just confuse the situation more).