Twig / Get Image Custom Metadata

Hi there

I try to get access to my custom metadata from an image in Twig. I already have tried a lot (inc. code below) and i don’t find it in the docs. Even if i dump the image (pimcore_image(‘image’)) my custom metadata is not available in the whole object.

Thanks a lot & happy weekend,
Fabian

 {{ dump(pimcore_image('image').metadata) }}
 {{ dump(pimcore_image('image').attributes )}}
 {{ dump(pimcore_image('image').properties )}}
 {{ dump(pimcore_image('image').metaData) }}
 {{ dump(pimcore_image('image').customMetaData) }}

Hi Fabian,

The pimcore_image editable returns an instance of Pimcore\Model\Document\Editable\Image. Here are some methods, that this editable class includes: https://pimcore.com/docs/pimcore/current/Development_Documentation/Documents/Editables/Image.html#page_Methods

To get the actual Pimcore Asset, you’d have to call the getImage() method. In Twig this could look something like this:

{% set imageEditable = pimcore_image('image') %}

{% if editmode %}
    {{ imageEditable|raw }}
{% else %}
    {% if not imageEditable.empty %}
        {{ dump(imageEditable.image.metadata) }} {# returns the whole metadata array #}
        {{ dump(imageEditable.image.metadata('alt')) }} {# returns the "alt" value #}
    {% endif %}
{% endif %}

Hope this helps,
Aaron

1 Like

Thanks a lot Aaron! :raised_hands: