模板中的参考Wa尾根页

问题描述 投票:0回答:1

当前,我使用此代码在基本模板中显示指向我的网站主页的链接:

{% if page.slug != 'homepage' %}
    <!-- insert link code here -->
{% endif %}

但是我喜欢重用我的代码,有时页面被称为其他名称。我想写的是像:

{% if page != request.site.root_page %}

但是这不起作用,尽管如果我在模板中显示这些字段的值,它们都相等或不符合预期...

<p>{{ request.site.root_page }} and {{ page }}<p>

结果:

<p>Contact and Contact</p> # On the root page

<p>Contact and Test</p> # On a different page

this相反的问题,因为数据不是特定于一页,而是特定于除一页之外的每一页。

我想念的是什么?

templates operators wagtail comparison-operators
1个回答
0
投票

[在解释问题的过程中,我也找到了答案。这是行不通的(我相信),因为尽管这些值看起来相同,但它们实际上是具有不同属性的对象,因此比较失败。

© www.soinside.com 2019 - 2024. All rights reserved.