【问题标题】:Current Shopify page URL for Blog page tagged view博客页面标记视图的当前 Shopify 页面 URL
【发布时间】:2017-03-18 14:43:38
【问题描述】:

我已将 Shopify 注册表单替换为 GetResponse 表单,并且我希望在提交表单后页面保持在同一位置。为此,我尝试动态生成当前 URL,以便可以将其作为返回 URL 传递。这是我的代码 sn-p 的样子:

    {% 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 正确返回 /blogs/news。但是,当我单击任何标签时,我会转到 URL 行 https://example.com/blogs/news/tagged/diy 或 https://example.com/blogs/news/tagged/bizarre。所以我试图让我的代码也处理这种情况,以便 current_url 获得值 /blogs/news/tagged/diy 或 /blogs/news/tagged/bizarre 等。

如果没有单个变量返回它,那也没关系。我只需要一种方法来返回标签值(如 diy 或 bizarre)。然后我可以连接 blog.url + /tagged/ +

这可能吗?

【问题讨论】:

    标签: shopify liquid getresponse


    【解决方案1】:

    您可以使用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 }}" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-07
      • 1970-01-01
      • 1970-01-01
      • 2016-11-15
      • 1970-01-01
      • 2015-08-01
      • 1970-01-01
      • 2022-12-01
      相关资源
      最近更新 更多