How to add collection.liquid to an existing page?

回眸只為那壹抹淺笑 提交于 2019-12-13 06:51:01

问题


In Shopify, I'm trying to take the template collection.liquid and render it in another page, just like embedding it. But i'm not sure how to accomplish that.

{% paginate collection.products by 50 %} 
{% include 'breadcrumb' %}
{% if settings.show_sort_by and collection.products_count > 1 %}
  {% include 'collection-sort' %}
{% endif %}
{% if current_tags.size > 0 %}
<h1>{{ current_tags.first }}</h1>
{% else %}
{% endif %}
{% if collection.description.size > 0 %}
<!--START HERO-->

<!--END HERO-->
{% endif %}
<!--START PRODUCT GRID-->
<section class="product-grid twelve columns alpha omega">
   <div id="collection_hero" class="collection_hero_class">
  <img src="http://carnegie.org/fileadmin/Media/News/press_releases/whitehouse.JPG"> 
  </div>
  {% if collection.products.size > 0 %}
    {% for product in collection.products %}
      {% include 'product-grid-item' %}
    {% endfor %}
  {% else %}
    <p id="no-products" class="animated fadeInUpBig">There aren't any products in this collection!</p>
  {% endif %}
</section>
<!--END PRODUCT GRID-->
{% include 'paging' %}
{% endpaginate %}

回答1:


I've been trying to do the same thing and kept getting errors.

Fixed it by making a new Snippet called list-collections and copying everything from list-collections.liquid into that. Then made a page template called page.list-collections.liquid and pasted this code into that before /div: {% include 'list-collections' %}

Then, I made a new page using the page.list-collections template, and entered my introductory text, images etc in that, which displays above product collections on the page when published :)




回答2:


Copy everything that's in collection.liquid and paste it into a new snippet (let's say you call it collection-copy.liquid).

Then, in the page you want to add the collections page to, just add {% include 'collection-copy' %}

That should just dump everything that's in collection-copy.liquid and output it to your page.




回答3:


The simplest way to do so is to :

  • Create a new page template for example : page.list-collections
  • Then place under : {{ page.content }} this line :

    {% section 'list-collections-template' %}

Now create a new page in Shopify then select the new page template. Normally you should be able to add new collections in the "Customize" section of your page !



来源:https://stackoverflow.com/questions/29338197/how-to-add-collection-liquid-to-an-existing-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!