2015-10-15 490 views
0

如何在Shopify中創建自定義鏈接?如何在shopify中創建自定義鏈接

此鏈接至產品類別{{product_type | link_to_type}}

的代碼看起來像這樣

{% for product_type in collection.all_types %} 
    {{ product_type | link_to_type }} 

我想添加一個「查看更多」鏈接這個鏈接指向同旁邊的鏈接。那可能嗎?

我試過,但他們不工作。

{{ '(view more)' | link_to_product_type }} 
{{ '(view more)' | link_to_type }} 
{{ '(view more)' | link_to: types?q=product_type }} 
{{ '(view more)' | link_to: 'types?q='product_type }} 
{{ '(view more)' | link_to: types?q=type }} 

任何幫助理解

回答

1

這可以通過鏈接上的replace(或replace_first)濾波器來實現。

{% for product_type in collection.all_types %} 
    {{ product_type | link_to_type | replace_first: '</a>', ' (view more)</a>' }} 
{% endfor %} 

,這將產生沿東西線:

<a href="/collections/types?q=Type1" title="Type1">Type1 (view more)</a> 
<a href="/collections/types?q=Type2" title="Type2">Type2 (view more)</a> 

你可以改變的替換/ replace_first到任何你想要的(view more)部分,但要確保它與</a>結束,關閉標籤並保留它之前的空間,所以它不會出現爲Type1(view more)

+0

非常感謝!有效!這看起來有點哈克,但非常感謝你! –

+0

不客氣!我從開發Shopify主題中學到的一件事是,您必須非常有創意才能獲得您想要的結果。只要你願意嘗試以一種他們不打算的方式工作,任何事情都是可能的。 –

相關問題