collection products

zurain
Excursionist
24 0 5

i created a collection named new i put products in it now i want to fetch this products on another page with liquid our any other code method

Replies 5 (5)
Niki_K
Shopify Partner
440 45 118

Hi @zurain

if you want to get all products in a collection and e.g. iterate through these products, try this piece of code:

it.

{% for product in collections.COLLECTIONHANDLE.products %}
      {{ product.title }}
{% endfor %}

This code will iterate through a collection and render products titles of all products.

Let me know if this works! 

Send me a link to your store to niki@hey.com and I'll help you out.
For more info what I do, visit my agency website ecommercepot.com or my personal website nikikozak.me.
zurain
Excursionist
24 0 5

Already done with this code thanks

 

 

<h1 class="prod">{{ collection.title }}</h1>

{%- if collection.description != blank -%}
<p>{{ collection.description }}</p>
{%- endif -%}

<ul class="dis">
{%- for product in collection.products -%}
<li>

<div class="card" style="width: 18rem;">
<a href="{{ product.url | within: collection }}">
<div class="reveal"><img src="{{ product.featured_image.src | img_url: '1024x' }}" class="card-img-top" alt="...">
<img class="hidden" src="{{ product.images.last | img_url: '450x450' }}" alt="{{ product.images.last.alt | escape }}" />

</div></a>
<div class="card-body">
<h5 class="card-title">{{ product.title }}</h5>
<p class="card-text">{{ product.price }} Rs</p>
<form method="post" action="/cart/add">
<input type="hidden" name="id" value="{{ product.variants.first.id }}" />
<input class="inputcrt" min="1" type="number" id="quantity" name="quantity" value="1"/>
<input type="submit" value="Add to cart" class="btn crt" />
</form>
{% comment %}
<!-- <a href="{{ product.url | within: collection }}" class="btn btn-primary">Go somewhere</a>-->
{% endcomment %}
</div>
</div>

</li>
{%- endfor -%}
</ul>

zurain
Excursionist
24 0 5

this code is not working

{% for product in collections.COLLECTIONHANDLE.products %}
{{ product.title }}
{% endfor %}

i get my solution with this code below

<h1 class="prod">{{ collection.title }}</h1>

{%- if collection.description != blank -%}
<p>{{ collection.description }}</p>
{%- endif -%}

<ul class="dis">
{%- for product in collection.products -%}
<li>

<div class="card" style="width: 18rem;">
<a href="{{ product.url | within: collection }}">
<div class="reveal"><img src="{{ product.featured_image.src | img_url: '1024x' }}" class="card-img-top" alt="...">
<img class="hidden" src="{{ product.images.last | img_url: '450x450' }}" alt="{{ product.images.last.alt | escape }}" />

</div></a>
<div class="card-body">
<h5 class="card-title">{{ product.title }}</h5>
<p class="card-text">{{ product.price }} Rs</p>
<form method="post" action="/cart/add">
<input type="hidden" name="id" value="{{ product.variants.first.id }}" />
<input class="inputcrt" min="1" type="number" id="quantity" name="quantity" value="1"/>
<input type="submit" value="Add to cart" class="btn crt" />
</form>
{% comment %}
<!-- <a href="{{ product.url | within: collection }}" class="btn btn-primary">Go somewhere</a>-->
{% endcomment %}
</div>
</div>

</li>
{%- endfor -%}
</ul>

zurain
Excursionist
24 0 5

its not working

lucas05021
Excursionist
125 0 5

So have you solved this problem now?