CedricRobitaille / ecommerce-pattern-library

A term-long project redesigning an ecommerce website focusing on making a pattern library.
https://loving-brahmagupta-0deb11.netlify.com/pattern-library/
0 stars 0 forks source link

Homepage Template completed + questions. #6

Open CedricRobitaille opened 4 years ago

CedricRobitaille commented 4 years ago

Seen in the index.html page.

Questions:

  1. In using _products, how can I pick a random product, and specific products. This is relevant in the homepage as I want to display 'popular', 'random' and 'blog' in the smaller cards.

@thomasjbradley

thomasjbradley commented 4 years ago

You could do it with a for-loop, kinda like this:

{% assign random_products=site.products|sample:3 %}

{% endif %}

Where the |sample:3 will pick 3 random things from inside the products collection.

CedricRobitaille commented 4 years ago

@thomasjbradley When doing that, I get the terminal error of "Unknown tag 'endif' in landing.html" pointing to the {% assign random_products=site.products|sample:3 %}.

Here's what I have. I set the sample count to 1 since I only have one card made as of now. {% assign random_products=site.products|sample:3 %}

{% pattern cards/product-card data=product %}
  {% endif %}

Additionally, I would like to know how to seek a specific product on a page (ie: Place the newest product on the homepage).

thomasjbradley commented 4 years ago

Oh yeah! My code above is missing a whole line! And it has a typo! How did that happen?

{% assign random_products=site.products|sample:3 %}
{% for product in random_products %}

{% endfor %}
CedricRobitaille commented 4 years ago

@thomasjbradley That worked perfectly fine.

A final question I have regarding this page is, how can I display a card for a specific product. (ie: Popular or blog.

thomasjbradley commented 4 years ago

Something like this should work:

{% assign product=site.products[2] %}
{% pattern cards/product-card data=product %}