OctoberCMS,将记录字符串与字符串进行比较

OctoberCMS, comparing a record string to a string

我正在尝试清理 10 月 CMS 项目中的标题,但我 运行 遇到了问题。

我有一组页面设置为 "Singles",因此标题为 [category]-single 这不是很好。

因此,为此我尝试在 twig 中使用 [x] in [y] 函数作为 if 函数,如下所示;

{% else if ('single' in this.page.baseFileName) %}
<title>[formatted title]</title>
{% else %}

这没有帮助,并抛出一个 "Unexpected token "name" 值 "if"(预期 "end of statement block")。”异常。

我想不出任何变化(例如,将记录指针括起来),我在这方面陷入僵局。

有什么帮助吗?

您似乎正在向 else if 添加额外的空间,只需将其删除并使用 elseif

{% elseif ('single' in this.page.baseFileName) %}
{#  ^ use like this #}
<title>[formatted title]</title>
{% else %}

文档:https://twig.symfony.com/doc/2.x/tags/if.html

如有疑问请评论。