简体   繁体   English

如何在液体Shopify中进行插值

[英]How to interpolate in liquid shopify

I am editing title tags that was written by another developer in Shopify Liquid, unfortunately i am so confused about the syntax. 我正在编辑由Shopify Liquid中的另一个开发人员编写的标题标签,不幸的是,我对语法非常困惑。 I am trying to do ruby style interpolation in one of the edits. 我正在尝试在其中一项编辑中进行红宝石样式插值。 for example, 例如,

{% assign title_content = teacher.name %}
{% include "layout/page_title", title: title_content %}

in pure ruby, it would be something like this 在纯红宝石中,将是这样的

{% assign title_content = "the name of the teacher is #{teacher.name}" %}

which will out give the output "the name of the teacher is bla bla". 这将给出输出“老师的名字是bla bla”。 I would like to know if can do something like this with liquid shopify. 我想知道是否可以使用液体shopify做类似的事情。

You can use the capture tag to build your variable as follows: 您可以使用capture标记来构建变量,如下所示:

{% capture title_content %}
the name of the teacher is {{ teacher.name }}
{% endcapture %}

Alternatively, you should be able to use the append filter during assignment: 或者,您应该能够在分配期间使用append过滤器:

{% assign title_content = "the name of the teacher is " | append: teacher.name %}

In any case, Liquid is supposed to be a "safe" templating language. 无论如何,Liquid应该是一种“安全”的模板语言。 As such, it will be less expressive then eg ERB which allows you to use arbitrary Ruby code. 因此,它的表现力不如例如ERB,后者允许您使用任意的Ruby代码。 This however ensures that normal users can enter and update the templates without risking arbitrary code execution on the server. 但是,这确保普通用户可以输入和更新模板,而不会冒在服务器上执行任意代码的风险。

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

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