我有一个话题列表:
list1 = [topic1, topic2, topic3, topic4, topic5, topic6]
我想要将另一个列表与此列表进行比对:
list2 = [topic2, topic4, topic6]
类似这样的内容:
{% if list2.items in list1 %}
在此处,需要检查list2中的每个项是否在list1中。如果list2中的任何一项或所有项都在list1中,则返回True。我觉得这很简单,但是我似乎找不到有用的信息。
完整示例:
{% set list1 = [topic2, topic4, topic6] %}
{% for post in posts %}
{% set list2 = [topic1, topic2, topic3, topic4, topic5, topic6] %}
{% for topic in list2 %}
{% if topic in list1 %}
{# output of post list based on conditions #}
{% endif %}
{% endfor %}
{% endfor %}
** 我正在使用没有服务器端访问权限的cms,因此我只能使用模板语言进行工作。
[item for item in list1 if item in list2]
- ryugie