phpsymfonyezpublishezplatform

ezplatform extracting the uri of an image for the current language of the current site access


Is there a best practice to extract the uri of an image in the current translation of the current site access in twig?

We have an object with a translatable image field. Rendering the image with the helper: ez_render_field works fine.

But I now need to also extract the uri of the image for the current siteaccess but cannot find a way of doing this.

Trying to use the ez_field just results in

{{ ez_field(content, "image_1").uri }}

An exception has been thrown during the rendering of a template ("Catchable Fatal Error: Object of class eZ\Publish\API\Repository\Values\Content\Field could not be converted to string").

The content object looks like: enter image description here


Solution

  • here is the standard way to achieve this.

    where image is the field's name and teaser is the image variante you defined. by default you have original , small , large and ....

    {% set imgAlias = ez_image_alias( content.getField( "image" ), content.versionInfo, 'teaser' ) %}
    {{ dump(imgAlias.url) }}
    

    ( imgAlias.url is what you are looking for. )

    here is the link to Documentation: https://doc.ez.no/display/DEVELOPER/ez_image_alias