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
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...
- shop.url
- shop.domain
- page.url
- collection.url
- product.url
- blog.url
- article.url
- 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 %}