I’m trying to get a Shopify collection page to display different .js embeds on a specific part of the page, depending on the URL of the current page.
Can this be done using {% if page.url == %}
if so, how would I have variants of page URLs and specific embed codes?
The page URL looks like this:
https://www.example.com/collections/technology/technology-connected-home
The embed code looks like this:
<script type="text/javascript" src="https://apps.example.com/app/js/18218989163.js"></script>```
3
Answers
Each Shopify store has different types of pages: index (aka home), product, collection, page, blog, article, and cart. Here is the full list of page types.
So, this
page.url
will only work on a page object of typepage
for all other types you need to use the proper page object to get theurl
:collection.url
product.url
In your case I’d suggest using
case/when
, add your logic in a snippet andrender
it intheme.liquid
.Here is an example:
ref
You gonna have to check for
request.page_type
before creating yourcase/when
or another approach would be to check the type at the top of the snippet, like:This isn’t a bulletproof solution, however it should be enough for you to build on top of it.
Good luck!
I recommend using page.handle and identifying the handle. I do not believe page.url will do what you need
You can also try this as handle can never be changed.