You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在BigCommerce Stencil代码中获取当前页面的完整URL?

BigCommerce获取带查询参数的路径解决方案

你遇到的问题是settings.request.absolute_path只返回不含查询参数的路径(比如/cat/),没法匹配带?page=5的完整路径或URL。要解决这个问题,你可以用BigCommerce提供的另外两个内置变量:

  • 获取带查询参数的相对路径:使用{{ settings.request.path_with_query }},它会返回/cat/?page=5这种格式。
  • 获取带查询参数的完整绝对URL:使用{{ settings.request.url }},它会返回https://testing.com/cat/?page=5这种格式。

把你的判断代码改成下面两种形式之一即可:

匹配相对路径的写法

{{#if settings.request.path_with_query '==='/cat/?page=5' }}
    <meta name="description" content="The fifth page of cat products available.">
{{/if}}

匹配完整URL的写法

{{#if settings.request.url '===' 'https://testing.com/cat/?page=5' }}
    <meta name="description" content="The fifth page of cat products available.">
{{/if}}

这两个变量属于settings.request对象的内置属性,官方文档里的settings对象结构中包含这些属性,能直接在模板中调用。

内容的提问来源于stack exchange,提问作者Jimil

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 12:37:03