Shopify - 将 Int 转换为 Liquid 中的字符串

Shopify - Convert Int to String in Liquid

如何在 liquid 中将数据类型从数字更改为字符串?

这可用于在块内创建动态 css classes。但是,如果它以整数形式出现,则不会被识别为 class.

{{block.id}} // Integer

我已经在下面回答了我自己的问题以及一个例子。

加引号...

{% for block in section.blocks %}
  {% assign blockId = "{{block.id}}" %}
  <style>
    .{{blockId}} .text-color {
      color: {{block.settings.text_color}}
    }
  </style>

  <div class="{{blockId}}">
    <span class="text-color">I am whatever color you set me to</span>
  </div>
{% endfor %}

我找到了更好的解决方案,直接投吧:

{% assign valueyouwant = intValue | string %}

看起来效果不错。 :)

对我来说 | string 没用所以我用了这个

{% assign variant_id = variant.id | append: "" %}