【发布时间】:2019-04-09 08:46:58
【问题描述】:
在 Shopify 中,我正在尝试在我的 shopify 商店中构建当前标签的字符串。
如果我在页面上:
mysite.com/collections/all/tag1+tagC+tag4
我需要能够将当前标签作为一个没有空格的完整字符串:
tag1+tagC+tag4
我的代码目前是这样的:
{% if current_tags %}
{% assign current_filters = '' %}
{% for tag in current_tags %}
{% if forloop.last == false %}
{{ current_filters | append: tag | handleize | append: '+'}}
{% else %}
{{ current_filters | append: tag | handleize}}
{% endif%}
{% endfor %}
{% endif %}
如果我那么输出
{{current_filters}}
我明白了
tag1+ tagC+ tag4
首先,如何在加号后没有空格的情况下获取此字符串?我试过使用 | strip 没有运气,也把我的代码放在 {%- -%}
其次,当我尝试将 current_filters 变量附加到另一个变量的末尾时,它是空白/空
{% assign current_collection = collection.handle %}
{% assign base_url = shop.url | append: '/collections/' | append: current_collection | append: '/' | append: current_filters %}
输出 base_url 只是返回
mysite.com/collections/all/
不是
mysite.com/collections/all/tag1+tagC+tag4
为什么当我只使用 {{current_filters}} 而不是 .. append: current_filters 时这会起作用
【问题讨论】:
标签: string append shopify liquid