When designing your site, there are many components that may require obtaining a single object (Category, Collection, Blog, Brand, or Product) for display. This can be accomplished by combining the assign  tag in combination with the appropriate find_{{object}} filter:

NOTE

When finding, you can specify either the object's name or slug. If an object cannot be found, the result will be an empty string.

Categories

{% assign my_category = 'My Category' | find_category %}
<a href={{ my_category.url }}/>{{ my_category.name }}</a>

{% assign other_category = 'other-category' | find_category %}
<a href={{ other_category.url }}/>{{ other_category.name }}</a>

Collections

{% assign my_collection = 'My Collection' | find_collection %}
<a href={{ my_collection.url }}/>{{ my_collection.name }}</a>

{% assign other_collection = 'other-collection' | find_collection %}
<a href={{ other_collection.url }}/>{{ other_collection.name }}</a>

Blogs

{% assign my_blog = 'My Blog' | find_blog %}
<a href={{ my_blog.url }}/>{{ my_blog.name }}</a>

{% assign other_blog = 'other-blog' | find_blog %}
<a href={{ other_blog.url }}/>{{ other_blog.name }}</a>

Brands

{% assign my_brand = 'My Brand' | find_brand %}
<a href={{ my_brand.url }}/>{{ my_brand.name }}</a>

{% assign other_brand = 'other-brand' | find_brand %}
<a href={{ other_brand.url }}/>{{ other_brand.name }}</a>

Products

{% assign my_product = 'My Product' | find_product %}
<a href={{ my_product.url }}/>{{ my_product.name }}</a>

{% assign other_product = 'other-product' | find_product %}
<a href={{ other_product.url }}/>{{ other_product.name }}</a>
Did this answer your question?