Shopify Liquid 是否有获取对象属性的管道?

发布于 2025-01-13 13:25:23 字数 638 浏览 3 评论 0原文

我目前有:

assign productCollectionHandle = menu.links | where: 'title', 'Product List' | first
assign productCollectionHandle = productCollectionHandle.url | remove: '/collections/'

有没有一种方法可以使用另一个管道来获取属性 url 来制作这一行?或者这总是必须使用多个分配

例如,我想使用括号(液体中不允许)

assign productCollectionHandle = (menu.links | where: 'title', 'Product List' | first).url | remove: '/collections/'

或使用类似的管道(我制作了这个管道)

assign productCollectionHandle = menu.links | where: 'title', 'Product List' | first | attribute: 'url' | remove: '/collections/'

I currently have:

assign productCollectionHandle = menu.links | where: 'title', 'Product List' | first
assign productCollectionHandle = productCollectionHandle.url | remove: '/collections/'

is there a way to fetch the property, url, using another pipe to make this one line? Or does this always have to use multiple assign?

For example, I'd like to use a parenthesis (not allowed in Liquid)

assign productCollectionHandle = (menu.links | where: 'title', 'Product List' | first).url | remove: '/collections/'

or use a pipe like (I made this pipe up)

assign productCollectionHandle = menu.links | where: 'title', 'Product List' | first | attribute: 'url' | remove: '/collections/'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

空宴 2025-01-20 13:25:24

您可以使用 map 过滤器从新数组中的链接中提取 URL 对象,并再次从该数组中获取第一项。

{{ menu.links | where: 'title', 'Product List' | first | map: "url" | first | remove: '/collections/' }}

您可以在此处找到有关 map 过滤器的更多信息:https://shopify.github.io/liquid/filters/map/" rel="nofollow noreferrer">https:// /shopify.github.io/liquid/filters/map/

我发现它有点矫枉过正,因为您添加了两个额外的过滤器并且使其难以阅读,但是...就像您所要求的那样。

You can use the map filter to extract the URL object from the link in a new array and get the first item from that array again.

{{ menu.links | where: 'title', 'Product List' | first | map: "url" | first | remove: '/collections/' }}

You can find more info about the map filter here: https://shopify.github.io/liquid/filters/map/

I find it a bit overkill since you are adding two additional filters and makes it hard to read but... it's a one liner like you asked.

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