我如何在双支架中截断物品购物
我需要截断从每个产品的标题中返回的字符数量
<div class="boost-pfs-filter-product-bottom">
<a href="[[itemUrl]]" class="boost-pfs-filter-product-item-title">
<h4 class="cl-product-card-name">[[itemTitle]]</h4>
</a>
<div class="cl-product-card-price">[[itemPrice]]</div>
<button class="quick-add-btn" [[quickAddAttr]] onclick='window.blubolt.quickadd.open("[[productHandle]]", {"stockMap": "{}" })'>
[[quickAddText]]
</button>
</div>
需要截断的元素是第3行上的[[itemTitle]],但是我不确定如何处理此问题,因为双方括号引起了问题。有什么想法在这里需要做什么?如果需要更多信息,请随时提出
I need to truncate the amount of characters that is returned from the title of each product but the file where this change needs to be applied has a set of double brackets wrapped around the specific element that needs truncating (see code)
<div class="boost-pfs-filter-product-bottom">
<a href="[[itemUrl]]" class="boost-pfs-filter-product-item-title">
<h4 class="cl-product-card-name">[[itemTitle]]</h4>
</a>
<div class="cl-product-card-price">[[itemPrice]]</div>
<button class="quick-add-btn" [[quickAddAttr]] onclick='window.blubolt.quickadd.open("[[productHandle]]", {"stockMap": "{}" })'>
[[quickAddText]]
</button>
</div>
The element that needs truncating is [[itemTitle]] on line 3, but i am not sure how to go about this as the double square brackets is causing issues. Any ideas what is needed to be done here? If any more info is needed feel free to ask
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这应该有效:
任何带有管道
|
在变量内的任何内容都将应用过滤器,在这种情况下,截断过滤器。过滤器是允许转换变量值的液体语言中可用的功能。在我的示例中,请注意
aria-label
仍在包含完整标题,因为它将使非常重要的标题和链接大纲对残疾人更有帮助。 CSS截断将使这一不必要。标题
还包括完整标题,该标题为鼠标用户提供了通过徘徊在其上扩展标题的方法。ARIA-LABEL
该按钮的ARIA-LABEL 对通过TAB导航的屏幕阅读器用户有帮助。否则,所有快速添加按钮具有相同的可访问名称。This should work:
Anything with a pipe
|
inside a variable will apply a filter, in this case the truncate filter. Filters are functions available in the Liquid language that allow transforming the variable value.In my example, please note also
aria-label
is still including the full title because it will render the very important heading and link outline more helpful for people with disabilities. CSS truncation would render this unnecessary.title
also includes the full title, which gives mouse users a way to expand the title by hovering on it.aria-label
for the button is helpful for screen reader users who navigate by means of tab. Otherwise, all Quick Add buttons have the same accessible name.