Timothy Hunkele
Timothy Hunkele

Reputation: 887

How to find domain of current request in Shopify liquid?

I have a store with multiple custom domains. I'm trying to find what domain is currently being requested.

Domains:

somestore.myshopify.com
store.customdomain1.com
store.customdomain2.com

When a request comes into store.customdomain1.com/collections is there a variable that will tell me it's from store.customdomain1.com ?

Upvotes: 5

Views: 8813

Answers (2)

Dave B
Dave B

Reputation: 3248

It looks like Shopify added a new Request object recently. I can't find much documentation, just the one example - but it looks like it addresses your need. Use {{ request.host }} to get the current actually-requested domain.

Reference: https://help.shopify.com/en/themes/liquid/objects/request#request-host

Upvotes: 12

Steph Sharp
Steph Sharp

Reputation: 11682

I don't think this is possible with liquid. There is {{ shop.url }}, but it appears to output your store's Primary Domain (Admin > Settings > Domains) rather than the actual domain the user requested.

I think you'd have to use Javascript instead. Either document.URL or window.location.href will give you what you want. See here.

Upvotes: 3

Related Questions