Shopify Liquid 是否有获取对象属性的管道?
我目前有:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
map
过滤器从新数组中的链接中提取 URL 对象,并再次从该数组中获取第一项。您可以在此处找到有关
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.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.