Handles are used to access the attributes of Liquid objects. Most objects in VersaCommerce (products, collections, blogs, articles, menus) have a handle. For example, a page with the title "About us" can be accessed in Liquid with the handle about-us.
<!-- the content of the About us page -->
{{ pages.about-us.content }}
By default, a handle is the title of the object in lowercase, with spaces and special characters replaced by hyphens (-).
A product with the title "Shirt" automatically gets the handle shirt. If a product with the handle shirt already exists, the handle is counted up: products named "Shirt" created later get handles like shirt-1, shirt-2 and so on.
To read the handle of a product, use product.handle.
How handles are created
Spaces in titles become hyphens in handles. For example, the title My shiny new title becomes the handle my-shiny-new-title.
Several consecutive spaces or special characters are replaced by a single hyphen. Spaces and special characters at the start and end are removed. For example, 70% cocoa sweet & salty bites!!! becomes 70-cocoa-sweet-salty-bites.
The handle also defines the URL of the object. A page with the handle about-us has the URL https://yourshop.example.com/pages/about-us.
Themes often rely on fixed handles for pages, products and menus. To keep design elements working and avoid broken links, VersaCommerce does not update the handle automatically when you change the title of an object. If you rename the page About us to About VersaCommerce, the handle stays about-us.
You can change a handle manually in the URL & Handle field.
Accessing handle attributes
Often you know the handle of the object whose attributes you need. Use the plural name of the object and then either square brackets ( [ ] ) or dot notation ( . ).
{{ pages.about-us.title }}
{{ pages["about-us"].title }}
About us
About us
Note that the example uses pages, not page.
You can also pass theme editor settings in this notation. This is useful for theme designers who want to let merchants choose which content their theme shows.
{% for product in collections[settings.home_featured_collection].products %}
{{ product.title }}
{% endfor %}
Great shoes
Cool shirt
Bad socks