Home > widget-integration > FilterService > getCurrentCollection
FilterService.getCurrentCollection() method
Gets current collection handle from URL.
Extracts the collection handle from the URL pathname by parsing the /collections/{handle} pattern. Returns undefined if not on a collection page.
Signature:
getCurrentCollection(): string | undefined;
Returns:
string | undefined
Collection handle string if on collection page, undefined otherwise
Remarks
Only extracts handle from standard /collections/handle URLs. Does not handle collection+tag URLs (e.g., /collections/handle/tag).
Example
Override to support custom collection URL patterns:
getCurrentCollection() {
// Try standard pattern first
const standard = super.getCurrentCollection();
if (standard) return standard;
// Try custom shop pattern (e.g., /shop/collection-name)
const customMatch = window.location.pathname.match(/\/shop\/([^/?#]+)/);
return customMatch?.[1];
}