簡體   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