Shopify 切片函数 returns '<'

Shopify slice function returns '<'

我需要在 Shopify 模板中提取货币符号。到目前为止我已经写了:

{% assign symbol = product.price | money %} //creates a variable which holds price with currency symbol
{% assign symbol = symbol | slice: 0 %} //should return first char out of a string
{{ symbol }} //prints the variable

不幸的是最后一行 returns < 字符。

现在我不知道如何进行这项工作。我知道 Shopify 可以通过 {{ shop.currency }} 方法显示货币,但它 returns 货币名称而不是货币符号。

检查商店设置中设置的货币格式 Settings > General > Standards and formats > Currency > Change formatting 有:

  • "HTML with currency"
  • "HTML without currency"

默认情况下它们是 ${{amount}} USD${{amount}},但由于您使用的是货币切换器,所以它们被包裹在 span.money 中。 <span class="money" >${{amount}} USD<span>

您可以使用过滤器 strip_html 轻松删除 span.money

{% assign symbol = symbol | strip_html | slice: 0 %}