1

eZ Publish 5 には、image 属性を持つクラスがあります。

twig テンプレート内で、属性パラメーターから相対 URL (「/var/site/storage/image/...」など) を取得できます。

ここで、絶対 URL が必要です。それを得る最良の方法はどれですか?

リクエスト情報を取得し、ベース URL を相対 URL に追加する必要がありますか? または、そのための組み込みメソッドがありますか?

ありがとう

4

2 に答える 2

0

はい、これが正解です。次のようないくつかのテストを前に追加することを忘れないでください:

データを取得するコンテンツ フィールドが存在するかどうか、およびそのフィールドが空でないかどうかを確認します。

{% if content.fields['myFieldIdentifier'] is defined and not ez_is_field_empty(content, 'myFieldIdentifier') %}
    {# do the job #}
{% endif %}

ImageFieldType がデフォルトでレンダリングされる方法は次のとおりです。

{% block ezimage_field %}
{% spaceless %}
{% if not ez_is_field_empty( content, field ) %}
<figure {{ block( 'field_attributes' ) }}>
    {% set imageAlias = ez_image_alias( field, versionInfo, parameters.alias|default( 'original' ) ) %}
    <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 }}" />
</figure>
{% endif %}
{% endspaceless %}
{% endblock %}
于 2015-10-13T09:13:57.440 に答える