Shopify nam daje mogućnosti korištenja alternativnih izgleda proizvoda pomoću objekta predložaka u Liquid-u. Recimo da želimo prikazati određene sekcije na nekim proizvodima, a druge na različitim proizvodima.
Ako bismo htjeli prikazati nešto na početnoj stranici, mogli bismo koristiti Liquid kod poput ovog:
{% if template == 'index' %}
{% include 'our-code-snippet' %}
{% else %}
{% endif %}
Ali kako bismo rekli: “ako proizvod koristi ovaj predložak, prikaži nešto, inače koristi zadani izgled”?
Za to možemo iskoristiti “template_suffix” svojstvo.

Kako stvoriti alternativni predložak proizvoda u Shopifyju
U uređivaču tema odabrali bismo predloške, dodali novi predložak i zatim odabrali želimo li stvoriti .liquid ili .json predložak. Dobar pristup bio bi korištenje svojstva “template_suffix”.

Adding an alternate product template to ShopifyNakon toga bismo otišli na stranicu proizvoda i odabrali predložak koji smo upravo stvorili.

Selecting an alternate product template on ShopifyAko želimo dohvatiti naš novi predložak putem Liquid-a, mogli bismo to učiniti pomoću svojstva “template_suffix”.

Shopify svojstvo “template_suffix”
Pravi primjer koji sam nedavno imao bio je zahtjev da se ne prikazuje cijena na stranici proizvoda ako taj proizvod koristi određene predloške.
Dakle, ako predložak proizvoda nije 'product-coming-soon' i nije 'affiliate-product', tada prikaži cijenu. Mogao sam koristiti i {%- unless -%}, ali sam pratio kod teme.
{%- if product.template_suffix != 'product-coming-soon' and product.template_suffix != 'affiliate-product' -%}
<p class="Product__Price">{{ product.selected_or_first_available_variant.price | money_with_currency }}</p>
{%- else -%}
{%- endif -%}
So, if the product template is not ‘product-coming soon” and it is not ‘affiliate-product’, show the price. I could have also used {%- unless -%} here, but I was following the theme’s code.
template-name.template-suffix.template-file-type
Shopify službena dokumentacija o alternativnim predlošcima kaže:
Alternate template files use the following name structure, where template-name is the template name, template-suffix is the alternate name, and template-file-type is the file type, which is either json or liquid:
This is a neat little trick I hope you may find useful.



Leave a comment