在某些页面上有条件地隐藏内容块的正确方法(Correct way to conditionally hide a content block on certain pages)
在Timber Twig模板中的某些页面上隐藏例如导航栏的最佳方法是什么。 尝试过包装导航栏元素
{% if post.title !== 'foo bar' %} // show the nav {% endif %}但这不起作用。
What is the best way to hide e.g. a nav bar on certain pages in Timber Twig templates. Have tried wrapping the navbar element in
{% if post.title !== 'foo bar' %} // show the nav {% endif %}But that doesn't work.
最满意答案
你不能在树枝上使用!== 。 你必须使用!=
工作片段: https : //twigfiddle.com/9l9lrc
{% set var = 'foo bar' %} {% if var != 'foo bar' %} <h2>Nav</h2> {% else %} <em>no-nav</em> {% endif %}You can't use !== in twig. You have to use !=
Working snippet: https://twigfiddle.com/9l9lrc
{% set var = 'foo bar' %} {% if var != 'foo bar' %} <h2>Nav</h2> {% else %} <em>no-nav</em> {% endif %}更多推荐
发布评论