twigezpublish

How to use ez_image_alias using twig


I wanna use ez_image_alias() function but I dunno what values I have to put in.

Do you have some examples of how to use this function using Twig ?


Solution

  • ez_image_alias Twig function accepts three parameters:

    Starting from your content which is available in a content variable in your template, you would use ez_image_alias function like this:

    {% set variation = ez_image_alias(
        ez_field(content, 'image'),
        content.versionInfo,
        'large')
    %}
    

    variation variable will now hold an instance of eZ\Publish\SPI\Variation\Values\ImageVariation object which you can use to render the image:

    <img src="{{ asset(variation.uri) }}" />