within
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.
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.
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.
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 <code>within</code> filter.
Code
{%- assign collection_product = collection.products.first -%}
{{ collection_product.url | within: collection }}Data
{
"collection": {
"products": [
{
"url": "/products/draught-of-immortality"
},
{
"url": "/products/glacier-ice"
},
{
"url": "/products/health-potion"
},
{
"url": "/products/invisibility-potion"
}
]
}
}Output
Output
/collections/sale-potions/products/draught-of-immortality