Prowadzimy rekrutację w Polsce do naszych biur w Krakowie i Tarnowie - dowiedz się więcej!

Shopify Liquid hints we use in our day-to-day work

Put the following Liquid syntax as the first line in any of a template file (index.liquid, product.liquid, etc.):

{% layout 'alternative' %}

In this instance, the default theme.liquid will be not be applied but rather the layout called alternative.liquid.

When it's useful? For example you want to master some sort of internal pseudo-API that supposed to fetch data using Liquid (Shopify is having different limits promoting the Liquid for data fetching) and you want to output this gathered by Liquid data in a form of JSON to later consume somewhere else.

It's possible to request that the layout file isn't applied. The syntax to request that a layout file isn't applied is:

{% layout none %}

This needs to be the first line at the top of the relevant template (index.liquid, product.liquid, etc.). This way if you formatted output in Liquid as a JSON you will get a nice JSON.

{{ collection.title }}
{% assign collection_handle = "collection-" | append: collection.handle %}
<ul>
  {% for link in linklists[collection_handle].links %}
   {% assign sub_collection = link.object %}
   <li><a href="{{ link.url }}">{{ link.title }}</a></li>
  {% endfor %}
</ul>

Useful when you want to display specific elements or UX on specific page or a template
For example If you want some code to be rendered on the homepage, you could use

{% if template.name == "index" %}
do something
{% endif %}

or if you want to check which template is being used, use this code below

{% if template contains 'page. templatename' %}
do something 
{% endif %}

There is way how to request some more information using Shopify docs

https://shopify.dev/docs/api/liquid/objects/request

null

Also some gems from this discussion about Liquid on Shopify Github

https://github.com/Shopify/liquid/issues/525

Shopify does know about some URLs that you might get some mileage from, depending what template you are on and what you are trying to do. All of the following will return URL-related value strings...

  1. shop.url
  2. shop.domain
  3. page.url
  4. collection.url
  5. product.url
  6. blog.url
  7. article.url
  8. article.comment_post_url

by: https://github.com/rickydazla

and

Hi I was able to get this by
{% assign current_url = '' %}

{% case template %}
{% when 'page' %}
{% assign current_url = page.url %}
{% when 'blog' %}
{% assign current_url = blog.url %}
{% when 'article' %}
{% assign current_url = blog.url %}
{% when 'collection' %}
{% assign current_url = collection.url %}
{% when 'product' %}
{% assign current_url = product.url %}
{% endcase %}

by: https://github.com/srinathperera101

Visit Our Office

16 Halcyon Ln
Aliso Viejo, CA 92656

Let's Talk

Phone: (415) 910-2498

call us
CUSTOMER SERVICE

We are happy to listen
suggest a feature, report a bug.

Submit Feature Request