Skip to content

closest object ​

Last updated View as Markdown

The nearest resource of each type for the section or block that is rendered.

Properties ​


NameTypeDescription
productproductThe nearest product
collectioncategoryThe nearest collection
pagepageThe nearest page
blogobjectThe nearest blog
articleobjectThe nearest article

Order ​

For each property, you get the first value found in this list:

  1. A setting of the same type on the section or block that is rendered: product, collection, page, blog or article.
  2. A closest. argument on the content_for tag of the block, for example closest.product: featured_product.
  3. A setting of the same type on the nearest parent block, or on the section.
  4. The resource of the template, for example the product on a product page.

A setting with a dynamic source as its value is skipped, for example {{ closest.product }}.

liquid
{% if closest.product %}
  <h2>{{ closest.product.title }}</h2>
{% endif %}