繁体   English   中英

Shopify - 在液体中将 Int 转换为 String

[英]Shopify - Convert Int to String in Liquid

如何将数据类型从数字更改为液体中的字符串?

这可用于在块内创建动态 css 类。 但是,如果它以 integer 的形式出现,则不会被识别为 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 | string不起作用,所以我使用了这个

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM