How to use Liquid to get contents of a text file

2022-01-26 21:08:35 标签 shopifyliquid

In Shopify I have some code that loops through a list of colors and displays them on the page:

{% assign colors = "red,orange,yellow,green,blue,indigo,violet" | split:"," %}
{% for color in colors %}<p>{{ color | capitalize }}</p>{% endfor %}

In order to make this as easy as possible for my non-technical client to update the available colors I'd love to be able to separate out the list in a separate file containing just the list (with no Liquid whatsoever)。 I tried putting it in a snippet。。。

snippets/colors。liquid

red,
orange,
yellow,
green,
blue,
indigo,
violet

and then changing the 1st line to:

{% assign colors = render "colors" | split:"," %}

but that gave an error: Liquid syntax error: Expected end_of_string but found string in "{{render 'colors' }}"。

Is there any way to just get the contents of a file and assign it to a String variable?

###capture grabsgrabs everything between tags as a string and assigns it to the。 variable named

{%- capture colors -%}
{%- render 'colors' -%}
{% endcapture %}
{% assign all_colors = colors | newline_to_br | split: '<br />' %}
{% for color in all_colors %}<p>{{ color | capitalize }}</p>{% endfor %}

snippets/colors。liquid

red
orange
yellow
green
blue
indigo
violet
阅读全文

▼ 版权说明

相关文章也很精彩
推荐内容
更多标签
相关热门
全站排行
随便看看

错说 cuoshuo.com —— 程序员的报错记录

部分内容根据CC版权协议转载;网站内容仅供参考,生产环境使用务必查阅官方文档

辽ICP备19011660号-5

×

扫码关注公众号:职场神器
发送: 1
获取永久解锁本站全部文章的验证码