呼叫图片已弃用 [英] Calling image is deprecated

查看:65
本文介绍了呼叫图片已弃用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在日志中注意到了这一点(访问 www.sk8whls.com 的主页时):

I just noticed this in my logs (when visiting my homepage on www.sk8whls.com):

从模板"teasers/wheels.twig"中调用模板"macros/html.twig"上的"image"从1.28版开始已弃用,2.0版不再支持.

Calling "image" on template "macros/html.twig" from template "teasers/wheels.twig" is deprecated since version 1.28 and won't be supported anymore in 2.0.

像这样的图像被称为(在预告片/wheels.twig中):

An image is called like this (in teasers/wheels.twig):

{{ html.image( image, 'thumbnail', fallback ) }}

我的宏如下:

{% macro image(image, size, fallback, alt, title, class ) %}
    {% set image    = image %}
    {% set size     = size|default('') %}
    {% set fallback = fallback|default(0) %}

    {% if image and image.src %}
        <img src="{{ image.src(size) }}" alt="{% if alt %}{{ alt }}{% else %}{{ image.alt }}{% endif %}" title="{{ title }}" class="{{ class }}" />
    {% elseif fallback %}
        <img src="{{ fallback }}" alt="fallback" title="" />
    {% endif %}
{% endmacro %}

我不确定为什么不赞成使用它,以及当v2.0支持消失时如何使它继续工作.

I'm not sure why it's deprecated and how I can keep it working when the support drops with v2.0.

推荐答案

从Twig 2.0开始,文件中导入的宏在子级中不可用不再使用模板(例如通过包含调用).你需要在您使用宏的每个文件中显式导入宏.

As of Twig 2.0, macros imported in a file are not available in child templates anymore (via an include call for instance). You need to import macros explicitly in each file where you are using them.

这意味着您还应该在 wheels.twig

这篇关于呼叫图片已弃用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆