I need to somehow pass a Liquid variable through a link to the next page

James_Morrison
New Member
3 0 0

I need to change the way a product page displays based on the page they arrived from.  If they click the link from one collection, I want it to theme the product page based on that collection.  Otherwise, I want to theme it differently.   The client does not want to have two separate products for each theme because there are a ton of products and it would mess up inventory tracking.

I have looked at using query variables or cookies, but apparently those are considered client-side and you can't access them from Liquid (Which is bunk because you can access them fine from other server-side languages like PHP)  Session variables are not allowed at all.  All the results I was able to find by searching either recommended using Javascript (won't work because you can't render different sections in JS) or Cart Attributes (which as near as I can tell won't work because they're only for adding custom fields to the product page when the customer is already there.

This seems like a trivial thing to be able to do so I figure there has got to be a way.  How can I pass a variable to Liquid on the following page?  It doesn't even need to persist like a cookie or a session variable, just needs to pass to the next page somehow.   Thanks for your help!

0 Likes
David_Weru
Trailblazer
154 14 34

Hello, @James_Morrison 

Liquid variables are persistent.

You can set one at the footer, and read the previous value at he header.

Everything that you render in between will be based on the value of that variable.

 

If you'd like further assistance, please let me know.

0 Likes
James_Morrison
New Member
3 0 0

Thanks for replying @David_Weru!  That's good to know that the liquid variables persist.  I did a test where I tried setting a variable on one page:

{% assign multi_page_template = 'shampoo' %}

and then displaying it on a new page

{{ multi_page_template }}

but it didn't pull the variable.  Does it *need* to be set in footer.liquid and then read in the following header.liquid?  Is there specific syntax that needs to be used?

0 Likes