COLLECTIONS.ALL_PRODUCTS - IF statement align center

Solved
Highlighted
New Member
3 0 0

Dear folks,

 

I have very strange issue. I went through a docs but couldn't find a right object.

 

I need to align "CENTER"  in collection block if there only == 1 product. So if there more than 1 product it will be aligned as in default "LEFT".

 

Here is code: 

Безымянный.png

{% if collections.all_products_count == 2 %}
      <style>
               .grid-product { margin: 0 auto }
      </style>
  {% endif %}
 
 
Interesting thing that is it working on: myshopify.com/collection/all-products
But it doesn't work on main page where I have also collection (like recomendation).
 
Please help.
0 Likes
Highlighted

Hi Grandpapa. Walter here from microDev (Shopify Partner).

 

I believe the issue you are having is due to the fact that on your home page you would have added a section called “featured-collection” which does not use the same css class as the regular product cards used on the other collection pages. Therefore, you will need to identify which class it is using for the products displayed on your home page and then target that class.

 

If you need further help with this or other customisations and support, please feel free to send me an email at support@microdev.today and we will see how we can help you achieve this.

0 Likes
Highlighted
New Member
3 0 0

Hey,

 

Thank for your reply. Unfortunatelly, it is not related to class. When I use put internal style without a if statement in featured products liquid, it works, but with if statement doesn't. So I am trying to identify if I am using correct code to get a count of collection

0 Likes
Highlighted

Success.

Hi


Looking into it a little deeper, if you are trying to add that code to a featured-collections or featured-products type file, the section won’t natively know what collection it is using. You will be specifying the collection it should use in the section settings. I am not sure exactly what your featured-products.liquid includes in terms of variables, but if in your section customisation you select a collection to use, you will need to change your if statement to replace the “collection’ part with the variable named featuredCollection or something similar, effectively a reference to the collection selected in the settings of that section. There will likely be a variable assignment line in that section which looks something along the lines of:

 

{% assign featuredCollection = collections[section.settings.collection] %}

If you can’t find anything that looks like the above or need more help, pop me an email and I’ll be happy to take a look at your store code for you.

1 Like
Highlighted
New Member
3 0 0

Very big thank you. Take care of yourself.

0 Likes