Shopify - 在Liquid中转换Int到字符串

问题描述 投票:0回答:1

如何在液体中把数据类型从数字改为字符串?

这可以用来在块中创建动态的css类。然而,如果它作为一个整数出现,它不被识别为一个类。

{{block.id}} // Integer

我在下面用一个例子回答了我自己的问题。

string integer shopify liquid coercion
1个回答
0
投票

添加引号...

{% 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 %}

0
投票

我找到了一个更好的解决方案,只要投下它。

{% assign valueyouwant = intValue | string %}

似乎很好用 :)

© www.soinside.com 2019 - 2024. All rights reserved.