2016-11-04 130 views
0

我已通过GetResponse表单替换了Shopify注册​​表单,并且希望页面在提交表单后留在同一位置。为此,我试图动态生成当前的URL,以便我可以将它作为返回URL传递。下面是我的代码片段看起来像:当前Shopify页面博客页面标记视图的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获取值/博客/新闻/标记/ diy或/博客/新闻/标记/奇怪等。

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

这可能吗?

回答

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 }}" /> 
+0

完美地工作!非常感谢。 – Swagata