within
string | within: collection
returns string
Generates a product URL within the context of the provided collection.
When the collection context is included, you can access the associated collection
object
in the product template.
Caution
Because a standard product page and a product page in the context of a collection have the same content on separate
URLs, you should consider the SEO implications of using the within
filter.
{%- assign collection_product = collection.products.first -%}
{{ collection_product.url | within: collection }}
{%- assign collection_product = collection.products.first -%}
{{ collection_product.url | within: collection }}
{
"collection": {
"products": [
{
"url": "/products/draught-of-immortality"
},
{
"url": "/products/glacier-ice"
},
{
"url": "/products/health-potion"
},
{
"url": "/products/invisibility-potion"
}
]
}
}
Output
/collections/sale-potions/products/draught-of-immortality
Was this page helpful?