使用 HubL(当我在 HubSpot 中构建模块时),我有两个数组:
topics
: 这是一个主题列表。all_tags
:这是系统中所有博客标签的数组。
如果我转储这些数组,它将返回:
{{ topics }}
打印以下内容:[Data, Accounting, Insight]
{{ all_tags }}
打印以下内容:[Accounting, Press, Data]
所以本质上,{{ topics }}
有一个系统中尚不存在的标签(“洞察力”)。
我要做的是创建第三个数组,它将包含来自上述两个数组的匹配结果。例如topics_final
,一旦返回,应该打印[Data, Accounting]
。
但是,在打印时{{ topics_final }}
,数组是空的。
我试过的:
<!-- this gets all tags -->
{% set all_tags = blog_topics( blog_id , 250) %}
<!-- create arrays -->
{% set topics = [] %}
{% set topics_final = [] %}
<!-- append topic data to the array -->
{% for item in module.add_topics.topics %}
{% set topic_option = item|striptags %}
{% do topics.append( topic_option ) %}
{% endfor %}
<!-- check if topic tags exists in HubSpot -->
{% for topics in all_tags %}
{% if topics in all_tags %}
{{ topics }}
<!-- results with above
Data, Accounting, Insight
-->
{% else %}
else
{% endif %}
{% endfor %}
有了上面,它只是打印出{{ topics }}
, 即使Insight
不在all_tags
数组中。
注意:标记Jinja2
为语法相似