shopify中 liquid使用记录

引入 liquid 文件 include
{%- if xxxxx -%}
  {% include 'media-360', path360: product.metafields.custom_fields.path_360,height: height %}
{%- endif -%}

上面代码表示

if 表达式成立
引入 文件 media-360.liquid
在该文件中可以拿到的变量 path360: product.metafields.custom_fields.path_360,height: height

引入 asset目录下的 资源
引入 js
<script src="{{ 'jquery-2.2.3.min.js' | asset_url }}"></script>
引入图片
<img 
	src="{{ '360-degrees.png' | asset_url }}" 
	alt="">
liquid 定义变量
{%- assign featured_media = product.price -%}
过滤器文档
添加默认值

使用过滤器 default
之后即为过滤条件

{%- assign featured_media = product.price | default: 100 -%}
使用 liquid 变量
传入liquid文件变量

引入media-360.liquid并传入了两个变量

  {% include 'media-360', path360: 'fuck',height: height %}
liquid文件中使用变量

media-360.liquid文件中使用变量

<div style="max-width:{{ height }}px; max-height:{{ height }}px;" />
liquid文件中 嵌入js 并使用变量
<script>
	const path360 = "{{ path360 }}"
	console.log(path360);
</script>
<div style="max-width:{{ height }}px; max-height:{{ height }}px;" />

<script>
	console.log("{{ height }}");
</script>
将多个liquid变量组合成一个变量

https://liquid.bootcss.com/tags/variable/
capture的变量都是 string类型

{% capture image_size %}
    {{ height }}x{{ height }}
{% endcapture %}

解释: 加入 height变量的值为200。则将 字符串 200x200 赋值给变量 image_size

{% capture media_class %}product-featured-media
{% endcapture %}
liquid中添加style

.lqiudi文件中直接添加 style标签

<style>
.watermark {
  width: 30%;
  height: 30%;
}
</style>

<div class="watermark">
 <img 
      src="{{ '360-degrees.png' | asset_url }}" 
      alt="Load and play video in Gallery viewer, 1-Turn Easy Jar Opener">
</div>
条件控制

https://liquid.bootcss.com/tags/control-flow/

case/when 相当于 switch
{% case section.settings.media_size %}
    {% when 'small' %}
      {%- assign height = 345 -%}
    {% when 'medium' %}
      {%- assign height = 530 -%}
    {% when 'large' %}
      {%- assign height = 720 -%}
    {% when 'full' %}
      {%- assign height = 1090 -%}
      {%- assign enable_image_zoom = false -%}
  {% endcase %}
循环
{%- for media in product.media -%}
  {% include 'media', media: media %}
{%- endfor -%}
if 语句
if
{% if product.title == 'Awesome Shoes' %}
  These shoes are awesome!
{% endif %}
else
{% if customer.name == 'kevin' %}
  Hey Kevin!
{% else %}
  Hi Stranger!
{% endif %}
elseif
{% if customer.name == 'kevin' %}
  Hey Kevin!
{% elsif customer.name == 'anonymous' %}
  Hey Anonymous!
{% else %}
  Hi Stranger!
{% endif %}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值