【问题标题】:TWIG not applying image style, but computing itTWIG 不应用图像样式,而是计算它
【发布时间】:2019-08-07 07:10:33
【问题描述】:

我有一个问题:我的 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-&gt;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;
    }

如何解决此警告?

【问题讨论】:

    标签: image drupal twig drupal-8


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2018-12-30
      • 2017-12-14
      • 1970-01-01
      • 1970-01-01
      • 2013-04-24
      • 1970-01-01
      • 1970-01-01
      • 2018-04-15
      • 2021-03-30
      相关资源
      最近更新 更多