TWIG 不应用图像样式,而是计算它

TWIG not applying image style, but computing it

我有一个问题:我的 TWIG 模板正在计算图像样式,但没有应用它。

news.html.twig中的代码:

<img class="emphasized" src="{{ field_news_emphasized|image_style('emphasized_image') }}" alt="{{ field_news_emphasized.alt }}"/>

field_news_emphasized = public://2019-07/img.jpg

图像看起来不错,因为我想用图像样式计算它 emphasized_image,但我仍然收到警告 Debug: Could not apply image style emphasized_image. in Drupal\twig_tweak\TwigExtension->imageStyle() (line 843 of modules\contrib\twig_tweak\src\TwigExtension.php).

TwigExtension.php 中第 843 行下方是:

    if (!$image_style->supportsUri($path)) {
      trigger_error(sprintf('Could not apply image style %s.', $style));
      return;
    }

如何修复此警告?

问题已解决 - 我试图在两种情况下应用图像样式,其中我没有加载 img(它是一个数组:exists、NULL、NULL、exists)。

{% if field_news_emphasized != NULL %} 解决了问题。