0

我已将 Shopify 注册表单替换为 GetResponse 表单,并且我希望在提交表单后页面保持在同一位置。为此,我尝试动态生成当前 URL,以便可以将其作为返回 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 正确返回 /blogs/news。但是,当我单击任何标签时,我会转到 URL 行https://example.com/blogs/news/tagged/diyhttps://example.com/blogs/news/tagged/bizarre。所以我试图让我的代码也处理这种情况,以便 current_url 获得值 /blogs/news/tagged/diy 或 /blogs/news/tagged/bizarre 等。

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

这可能吗?

4

1 回答 1

2

您可以使用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 }}" />
于 2016-11-05T12:38:10.700 回答