pri*_*iya 5 django django-templates wagtail
如何进行不区分大小写的字符串比较?
就我而言,当 topic.title 等于 page.slug 时,我需要添加一个menu_active类。但现在
所以我的条件失败了
nav_bar.html
{% for topic in landing_pages %}
<li role="presentation">
<a class="{% if topic.title == page.slug %}menu_active{% endif %}" href="/{{topic.slug}}/">{{topic.title}}</a>
</li>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
通过内置模板标签lower/upper 传递字符串,然后进行比较。
<a class="{% if topic.title|lower == page.slug|lower %}menu_active{% endif %}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1985 次 |
| 最近记录: |