液体代码在带有两个管道的数组中的第一个管道实例之前删除所有内容

发布于 2025-02-03 23:53:26 字数 602 浏览 3 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酸甜透明夹心 2025-02-10 23:53:26

您可以使用splitslice从液体代码过滤器获得所需的结果。
您还可以在文档中阅读有关这些过滤器的更多信息:

split

a href =“ https://shopify.dev/api/liquid/filters/string-filters#slice” rel =“ nofollow noreferrer”> slice

使用这样的使用:

{{ product.title | split: '|' | slice: 1, 2 }}

You can use the split and slice 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:

{{ product.title | split: '|' | slice: 1, 2 }}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文