液体代码在带有两个管道的数组中的第一个管道实例之前删除所有内容
99%的Shopify产品头衔看起来像:
品牌名称|产品名称
我添加了液体代码以删除品牌名称和“ |”管道角色:
{% assign product_title_trim = product.title | split: "| " %}
{{product_title_trim[1]}}
这成功地删除了品牌名称和管道,仅留下“产品名称”。
问题是我们有一些产品看起来像这样的产品:
品牌名称|产品名称|变体大
目标是1。删除品牌名称,2。卸下第一和第二管“ |”,以及3。保持“变体大”。最终标题看起来像这样:
产品名称变体大
我知道我需要1。首先在所需位置('brand Name |'),2。标题是产品名称|变体,删除第一个管道实例。在第一个之前删除所有内容,原始管道实例被证明是一个挑战。仅使用 管道的标题进行简单。如何在第一个管道实例之前删除所有内容,但是将第二个管道实例完好无损?然后,我可以轻松删除第二个管道实例。任何帮助将不胜感激!
99% of our Shopify product titles look like this:
Brand Name | Product Name
I have added liquid code to remove the Brand Name and "|" pipe character:
{% assign product_title_trim = product.title | split: "| " %}
{{product_title_trim[1]}}
This successfully removes the Brand Name and pipe leaving just "Product Name".
The issue is we have some products whose titles look like this:
Brand Name | Product Name | Variant Large
The goal is to 1. Remove the Brand Name, 2. Remove the First and Second Pipe "|", and 3. Keep the "Variant Large". The final title would look like this:
Product Name Variant Large
I know I need to 1. First split the array at the desired location ('Brand Name | '), 2. After the Array is split and the title is Product Name | Variant, remove the first pipe instance. Removing everything before the first, original pipe instance is proving to be more of a challenge. It is simple to do with a title with only one pipe. How can I remove everything before the first pipe instance, but leave the second pipe instance intact? Then, I can easily remove the second pipe instance. Any help would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
split
和slice
从液体代码过滤器获得所需的结果。您还可以在文档中阅读有关这些过滤器的更多信息:
split
a href =“ https://shopify.dev/api/liquid/filters/string-filters#slice” rel =“ nofollow noreferrer”> slice
使用这样的使用:
You can use the
split
andslice
filters from the liquid code to get the desired result.You can also read more about these filters in the documentation:
split
slice
Use like this: