博客页面标记视图的当前 Shopify 页面 URL

Current Shopify page URL for Blog page tagged view

我已将 Shopify 注册表单替换为 GetResponse 表单,我希望页面在提交表单后保留在同一位置。为此,我正在尝试动态生成当前 URL,以便我可以将其作为 return URL 传递。这是我的代码片段:

    {% assign current_url = '' %}

    {% case template %}
         {% when 'page' %}
               {% assign current_url = page.url %}
         {% when 'blog' %}
               {% assign current_url = blog.url %}
         {% when 'article' %}
               {% assign current_url = article.url %}
         {% when 'collection' %}
               {% assign current_url = collection.url %}
         {% when 'product' %}
               {% assign current_url = product.url %}
    {% endcase %}


<form action="https://app.getresponse.com/add_subscriber.html" accept-charset="utf-8" method="post">
<!-- Show the name field (required) -->
<input type="hidden" name="name"/>
<!-- Email field (required) -->
<input type="text" name="email"/>

<!-- Campaign token -->
<!-- Get the token at: https://app.getresponse.com/campaign_list.html -->
<input type="hidden" name="campaign_token" value="xxxxx"/>

<!-- Subscriber button -->
<input type="submit" value="Sign Me Up" onclick="javascript:window.alert('Thanks for entering your email address!');"/>
<!-- Add any optional code here (explained below) -->
<input type="hidden" name="thankyou_url" value="https://example.com{{ current_url }}"/>

正如您在案例陈述中看到的那样,我已经分别处理了所有页面类型。当用户位于主博客页面时(https://example.com/blogs/news), blog.url correctly returns /blogs/news. However when I click on any of the tags, I go to the URL line https://example.com/blogs/news/tagged/diy or https://example.com/blogs/news/tagged/bizarre。所以我试图让我的代码也处理这种情况,以便 current_url 获得值 /blogs/news/tagged/diy 或 /blogs/news/tagged/bizarre等

如果没有单个变量return也是可以的。我只需要一种方法来 return 标签值(比如 diy 或 bizarre)。然后我可以连接 blog.url + /tagged/ +

这可能吗?

您可以使用 current_tags 执行此操作。参考 https://help.shopify.com/themes/liquid/objects/current-tags#inside-collection-liquid

代码中的一个简单更改如下所示

{% capture current_url %}
  {% case template %}
    {% when 'page' %}{{page.url}}
    {% when 'blog' %}{% if current_tags %}/{{ current_tags.first | handleize }}{% endif %}
    {% when 'article' %}{{article.url}}
    {% when 'collection' %}{{collection.url}}{% if current_tags %}/{{ current_tags.first | handleize }}{% endif %}
    {% when 'product' %}{{product.url}}
  {% endcase %}
{% endcapture %}

<input type="hidden" name="thankyou_url" value="https://example.com{{ current_url | strip_newlines }}" />