【问题标题】:Join strings using Liquid使用 Liquid 连接字符串
【发布时间】:2018-10-28 20:54:34
【问题描述】:

在下面的代码中,我试图在元素上设置样式属性。我继承了别人的代码,所以不清楚两件事:

1 - 为什么 Liquid 对象 '{{ new.image }}' 用引号括起来/ 2 - 如何在下面的代码中使用px 加入宽度和高度的字符串值。以下代码不正确。

{% for news in page.carousel %}
  {% assign width = 1920 %}
  {% assign height = width | times: 20 | divided_by: 100 | times: 140 | divided_by: 100 %}
  <div class="item img-cover img-fixed {% if forloop.first %}active{% endif %}" style="background-image: url({% pic '{{ news.image }}' %}) width= '{{width | join: "px"}}'  height='{{height | join:"px"}}'">
  <h2>{{ news.text }}</h2>
  </div>
{% endfor %}

【问题讨论】:

    标签: string jekyll liquid static-site


    【解决方案1】:

    {% pic 来自自定义插件。你能说出它的名字吗?

    用液体连接字符串:

    width= '{{width}}px'
    

    width= '{{width | append: "px"}}'
    

    【讨论】:

      猜你喜欢
      • 2020-02-27
      • 1970-01-01
      • 2016-10-25
      • 2010-09-12
      • 2010-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多