Twig:如何正确链接两个 if 条件,其中一个条件包含 "not" 关键字?

Twig: How to correctly chain two if-conditions where one condition contains the "not" keyword?

我正在尝试在 twig 中写一个 if 语句,但似乎不起作用。

{% if content.thumbnail_uri != '' and '/podcasts/' not in content.thumbnail_uri %}

and 之前的第一个语句运行正常。

对于第二条语句,我想确保 content.thumbnail_url(这是从 JSON 字符串中提取的 string/URI)不包含子字符串 /podcasts/.

如何在 twig 模板中正确编写此 if 语句?

您可以使用大括号正确地对语句进行分组。

以下语法有效:

{% 
  if (content.thumbnail_uri is not empty)
  and ("/podcasts/" not in content.thumbnail_uri)
%}