Saji
April 2, 2021, 2:33am
1
What is the line of code used to navigate to a URL based on some condition, using Liquid Code (at server side) i.e WITHOUT using Javascript ?
(Here, I am not asking about client-side re-direction)
Something example like, if the product is out of stock out navigate to another page …
Thanks
John
1 Like
system
April 2, 2021, 4:26am
2
Hi @Saji
Aibek is here from Speedimize.io
If we are not mistaken, then liquid does not have the ability to redirect.
Use as below:
{% if product.available %}
{% endif %}
Hope that helps you.
2 Likes
Saji
April 2, 2021, 8:47am
3
Thanks Aibek.
But this was not the solution I am looking for. If you know .Net, I am looking for something similar to Server.Transfer functionality.
Let me reiterate another example:
If the product is out of stock, navigate to the URL, the URL is saved in a shopify metafield .
Now, here I am not sure how we can pass a variable/metafield to a javascript for redirection.
Thanks
John
1 Like
system
April 2, 2021, 9:17am
4
Hey @Saji
Thanks for getting back to me and clarifying with an example, now it’s much better.
If URL is stored in product meta-fields, you can use this piece of code. Just put the correct meta field name.
{% if product.available %}
{% endif %}
Otherwise, if a liquid file stored at your server, to make a redirect from the server you need to make a Shopify API request to get product data, and then you can redirect via .net
Maybe that helps you.
Saji
April 2, 2021, 1:09pm
5
Hey @Anonymous
Does not work.
I have tried like this…
{% if product.available != true %}
{%assign redirecturl = product.collections[0].metafields.breadcrumbs.Current-url%}
{% endif %}
It looks like an infinite loop, loads…reloads…reloads…
Please enlighten me if I am wrong.
Can we call Liquid code {{ .. }} from inside a ?
Thanks
John
system
April 5, 2021, 11:10am
6
Hi @Saji
First of all, yes, liquid code is supported inside the tag.
Current-url-not written this way. Try starting with a small letter and using a lower space. It should work like this:
{% assign redirecturl = product.collections[0].metafields.breadcrumbs.current_url %}
And to check, try printing this variable in any of the tags. For example, h1.
{{ redirecturl }}
See what’s printed out there. If your site is live, it is better to use Then your visitors won’t notice the text.
Try it and let us know.
1 Like