The handle object returns the handle of these resources:

  • blogs
  • articles
  • collections
  • pages
  • products

You can view and edit the handle of a resource in the shop admin in the search engine preview section.

Targeting webpages

Use the handle object to target specific pages when you want to show different content on different pages. For example, to show a message only on a page with the handle top-secret, add this code to the theme.liquid template:

{% if handle contains 'secret' %}
  <p>Discretion! This stays between you and us.</p>
{% endif %}
<!-- On a page with the title Top Secret and the handle top-secret -->
Discretion! This stays between you and us.

Webpages that don't have their own handle

Not all pages have their own handle.

The home page of your shop, which uses the index.liquid template, returns no value for handle:

{% if handle %}
  <p>You are viewing a product, a collection, a page, a blog or a blog article.</p>
{% else %}
  <p>You must be somewhere else. Have fun!</p>
{% endif %}
<!-- On a store's home page -->
<p>You must be somewhere else. Have fun!</p>

Special characters

Because handles are used for storefront navigation, they may only contain alphanumeric characters (a-z, 0-9). These characters cannot be used:

  • accents such as umlauts and other diacritics
  • symbols such as @, # or $
  • spaces

Spaces are converted to hyphens. Other characters are removed or converted to an equivalent standard ASCII character.