簡體   English   中英

博客頁面標記視圖的當前Shopify頁面URL

[英]Current Shopify page URL for Blog page tagged view

我已經用GetResponse表單替換了Shopify注冊​​表單,我希望頁面提交后頁面保持原樣。 為此,我試圖動態生成當前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 }}"/>

正如您在case語句中看到的那樣,我已經分別處理了所有頁面類型。 當用戶進入博客主頁面( 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或離奇)。 然后,我可以將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 }}" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM