Shopify Section Rendering API

参考链接:https://shopify.dev/docs/api/ajax/section-rendering

ajax通过section id 获取特定模板的html

id可通过liquid模板拿到{{ section.id }}

获取首页的特定的section,比如a.liquid

    fetch(window.Shopify.routes.root + "?section_id=a")
      .then(res => res.text())
      .then(domText => {
        console.log(domText);
      }
    )

就会得到section a的所有html字符串

获取一组section,比如首页的a.liquid和b.liquid

    fetch(window.Shopify.routes.root + "?sections=header,footer")
      .then(res => res.json())
      .then(domText => {
        console.log(JSON.parse(domText));
      }
    )

得到以下response

获取集合页面的特定section

    fetch(window.Shopify.routes.root + "/collections/{collection_handle}?section_id={section-id}")
      .then(res => res.text())
      .then(domText => {
        console.log(domText);
      }
    )

获取产品页面的特定section

    fetch(window.Shopify.routes.root + "/products/{product_handle}?section_id={section-id}")
      .then(res => res.text())
      .then(domText => {
        console.log(domText);
      }
    )

注意:如果产品A的所属模板是product A模板,那么请求section rendering api只能获取到product A模板的某个section,collection、article同理。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值