在某些页面上显示link_list菜单

发布于 2025-01-26 23:00:20 字数 555 浏览 2 评论 0原文

我想在我的产品页面上的标题中显示某个菜单,而不是在网站范围内显示。

我的theme.liquid文件具有{%章节'header'%}< body>中标记,因此我的标头在所有页面都如预期的。

部分/header.liquid具有以下架构:

{% schema %}
{
  "name": "Header",
  "settings": [
    {
      "type": "link_list",
      "id": "menu",
      "default": "main-menu",
      "label": "Heading Navigation Menu"
    }
  ]
}
{% endschema %}

我认为当您进入Shopify上的主题编辑器时,您可以单独选择我的'heading菜单中显示的内容导航菜单“每页”部分(主页,收藏,博客等),但此时是静态的。理想情况下,我可以进入那里,并在导航设置中为某些页面选择一个不同的菜单。

I'd like to get a certain menu to display in the header on my product page instead of site-wide.

my theme.liquid file has the {% section 'header' %} tag within the <body> so my header is showing fine on all pages as expected.

the sections/header.liquid has the following schema:

{% schema %}
{
  "name": "Header",
  "settings": [
    {
      "type": "link_list",
      "id": "menu",
      "default": "main-menu",
      "label": "Heading Navigation Menu"
    }
  ]
}
{% endschema %}

I thought when you go into the theme editor on Shopify that you'd be able to individually select what shows up in the in menu part of my 'Heading Navigation Menu' section per page (Home, Collections, Blog, etc.), but at this point it's static. Ideally I'd be able to go in there and select a different menu I create in the Navigation setting for certain pages.

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

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

发布评论

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

评论(1

一抹苦笑 2025-02-02 23:00:20

我最终使用开关语句和模板对象来处理此操作。

在我的部分/header.liquid的导航栏中,我创建了Switch语句:

<nav>
  <ul>
  {% case template.name %}
  {% when 'article' %}
    <li>
      Show that
    </li>
  {% when 'cart' or 'blog' or 'product' %}
    <li>
      Show that and this
    </li>
  {% else %}
    <li>
      Show this
    </li>
  {% endcase %}
  </ul>
</nav>

您可以将您喜欢的任何元素放在各个情况下,它将检查您的模板名称所在。

两者的shopify文档:

不确定这是否是最有效的方法,但希望这可以帮助任何人尝试尝试完成类似的事情。

I ended up handling this with a switch statement and the template object.

In my navigation bar in my sections/header.liquid I created the switch statement:

<nav>
  <ul>
  {% case template.name %}
  {% when 'article' %}
    <li>
      Show that
    </li>
  {% when 'cart' or 'blog' or 'product' %}
    <li>
      Show that and this
    </li>
  {% else %}
    <li>
      Show this
    </li>
  {% endcase %}
  </ul>
</nav>

You can put whatever element you like inside of the individual cases and it will check whatever your template name is to put display that element.

Shopify documentation for both:

Not sure if this is the most effective way to do this, but hope this helps anyone trying to accomplish something similar.

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