我如何在双支架中截断物品购物

发布于 2025-02-07 11:39:14 字数 992 浏览 2 评论 0原文

我需要截断从每个产品的标题中返回的字符数量

<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

picture1

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

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

发布评论

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

评论(1

清风夜微凉 2025-02-14 11:39:14

这应该有效:

<div class="boost-pfs-filter-product-bottom">
            <a href="[[itemUrl]]" class="boost-pfs-filter-product-item-title">
                <h4 class="cl-product-card-name" aria-label="[[itemTitle]]" title="[[itemTitle]]">[[itemTitle | truncate: 20]]</h4>
            </a>
            <div class="cl-product-card-price">[[itemPrice]]</div>
            
            <button class="quick-add-btn" [[quickAddAttr]] onclick='window.blubolt.quickadd.open("[[productHandle]]",  {"stockMap": "{}" })' aria-label="[[quickAddText]] [[itemTitle]]">
                [[quickAddText]]
            </button>
        </div>

任何带有管道|在变量内的任何内容都将应用过滤器,在这种情况下,截断过滤器。过滤器是允许转换变量值的液体语言中可用的功能。

在我的示例中,请注意

aria-label仍在包含完整标题,因为它将使非常重要的标题和链接大纲对残疾人更有帮助。 CSS截断将使这一不必要。

标题还包括完整标题,该标题为鼠标用户提供了通过徘徊在其上扩展标题的方法。

ARIA-LABEL该按钮的ARIA-LABEL 对通过TAB导航的屏幕阅读器用户有帮助。否则,所有快速添加按钮具有相同的可访问名称。

This should work:

<div class="boost-pfs-filter-product-bottom">
            <a href="[[itemUrl]]" class="boost-pfs-filter-product-item-title">
                <h4 class="cl-product-card-name" aria-label="[[itemTitle]]" title="[[itemTitle]]">[[itemTitle | truncate: 20]]</h4>
            </a>
            <div class="cl-product-card-price">[[itemPrice]]</div>
            
            <button class="quick-add-btn" [[quickAddAttr]] onclick='window.blubolt.quickadd.open("[[productHandle]]",  {"stockMap": "{}" })' aria-label="[[quickAddText]] [[itemTitle]]">
                [[quickAddText]]
            </button>
        </div>

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.

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