Wednesday 14 January 2015 9:27:20 am - 1 reply
Hi,
We have a problem on rendering of an ez image field with the function template "ez_render_field". We discover that in the default case, the alias "original" is rendered (file "EzPublishCoreBundle....../content_fields.html.twig" :
<img src="{% if imageAlias %}{{ asset( imageAlias.uri ) }}{% else %}//:0{% endif %}"{% if imageAlias.width is defined %} width="{{ imageAlias.width }}"{% endif %}{% if imageAlias.height is defined %} height="{{ imageAlias.height }}"{% endif %} alt="{{ field.value.alternativeText }}" />
The problem is that the imageAlias orginal has not width and height by default. Why ? We want to display the image uploaded by default, but we want also to define the sizes in the HTML rendered block.
To solve the problem, we had to override the fields template and get the with and height directly in the field like this :
{% block ezimage_field %} {% spaceless %} {% if not ez_is_field_empty( content, field ) %} {% set imageAlias = ez_image_alias( field, versionInfo, parameters.alias|default( 'original' ) ) %} {% set width = field.value.width %} {% set height = field.value.height %} {% if imageAlias %} <img {% if parameters.class is defined %}class="{{ parameters.class }}"{% endif %} src="{{ asset( imageAlias.uri ) }}" {% if imageAlias.width %}width="{{ imageAlias.width }}"{% else %}width="{{ width }}"{% endif %} {% if imageAlias.height %}height="{{ imageAlias.height }}"{% else %}height="{{ height }}"{% endif %} alt="{{ field.value.alternativeText }}"/> {% endif %} {% endif %} {% endspaceless %} {% endblock %}
Is there another solution mabe ?
Tkx for your help,
Modified on Wednesday 14 January 2015 3:01:41 pm by Clem PERISCOPE
Tuesday 21 July 2015 6:24:39 pm
Hello,
Same problem here. Your solution works.
But I created a pull request to add missing height and width in the kernel : https://github.com/ezsystems/ezpublish-kernel/pull/1349
Nicolas
You must be logged in to post messages in this topic!