Skip to content

Image Twig functions

Image rendering

To render images, use the ez_render_field() Twig function with the variation name passed as an argument, for example:

1
2
3
4
5
6
7
{{ ez_render_field(content, 'image', {
    'template': '@ezdesign/fields/image.html.twig',
    'attr': {class: 'thumbnail-image'},
    'parameters': {
        'alias': 'small'
    }
}) }}

Image information

ez_image_alias()

ez_image_alias() returns the selected variation of an image Field.

Argument Type Description
field eZ\Publish\API\Repository\Values\Content\Field The image Field.
versionInfo eZ\Publish\API\Repository\Values\Content\VersionInfo The VersionInfo that the Field belongs to.
variantName string Name of the image variation to be used. To display the original image variation, use original as the variation name.
1
{% set thumbnail = ez_image_alias(imageField, content.versionInfo, 'small') %}

Tip

You can access the name of a variation from the variation object with variation.name. You can, for example, use it as parameter in the ez_render_field() Twig function.

ez_content_field_identifier_first_filled_image()

ez_content_field_identifier_first_filled_image() returns the identifier of the first image field that is not empty.

Caution

This function works only for Image Fields. It does not work for ImageAsset Fields.

Argument Type Description
content eZ\Publish\API\Repository\Values\Content\Content Content item to display the image for.
1
{% set firstImage = ez_content_field_identifier_first_filled_image(content) %}

Examples

You can use ez_content_field_identifier_first_filled_image() to find and render the first existing image in an article:

1
2
{% set firstImage = ez_content_field_identifier_first_filled_image(content) %}
{{ ez_render_field(content, firstImage) }}