Reputation: 914
When you have a page like domain.com/products/product_name?variant=variant_id
This means that the page that is being loaded is the variant of the specific product (product_name) here since there's the url query "variant".
Like for example, 1 tshirt has many variant colors, so the same design can have different variant pages (this is just a simple example) I want to check if the current page is a variant of a product or not before it loads through liquid. How?
Upvotes: 0
Views: 3598
Reputation: 151
{% if product.has_only_default_variant %}
// not
{%- else -%}
// yes
{%- endif -%}
Upvotes: 0
Reputation: 427
product.selected_variant
returns the variant object.
To get the current variant id use product.selected_variant.id
Upvotes: 1
Reputation: 12943
You can use product.selected_variant
that will return the variant ID if the get parameter is present or not.
Based on that you will be able to write a simple if:
{%- if product.selected_variant -%}
{%- else -%}
{%- endif -%}
Upvotes: 0