smi*_*der 7 string integer coercion liquid shopify
如何将液体中的数据类型从数字更改为字符串?
这可用于在块内创建动态 CSS 类。但是,如果它作为整数出现,则不会将其识别为类。
{{block.id}} // Integer
Run Code Online (Sandbox Code Playgroud)
我在下面回答了我自己的问题并举了一个例子。
对我来说| string不起作用,所以我用了这个
{% assign variant_id = variant.id | append: "" %}
Run Code Online (Sandbox Code Playgroud)
添加引号...
{% 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 %}
Run Code Online (Sandbox Code Playgroud)