-
-
Save gbrits/6dc2d72d2b63d0b278c7c1b16e5492f1 to your computer and use it in GitHub Desktop.
<!-- Add this at the top of your page template --> | |
{%- capture contentForQuerystring -%}{{ content_for_header }}{%- endcapture -%} | |
{%- assign pageUrl = contentForQuerystring | split:'"pageurl":"' | last | split:'"' | first | split:'.myshopify.com' | last | | |
replace:'\/','/' | | |
replace:'%20',' ' | | |
replace:'\u0026','&' | |
-%} | |
{%- unless pageUrl contains "?" -%}{% break %}{%- endunless -%} | |
{%- assign pageQuerystring = pageUrl | split:'?' | last -%} | |
{%- assign tag = pageQuerystring | split:'=' | last -%} | |
{%- assign query_tags = tag | split: "," -%} | |
<!-- Try adding ?tag=blah,blah2,blah3" at the end of your page's URL. --> | |
<!-- // Example: --> | |
{{ query_tags | json }} |
Hi @Christopher-Hayes, you're right. I have successfully used the above for minor filtering, but it is an imperfect solution. It is also (now) an outdated solution, with the advent of 2.0 Themes in Shopify.
@gbrits I was hoping you might help me. What is the current solution to grab the UTM parameters and pass them into liquid variables to use as hidden fields in form submits? Thanks!
@gbrits I was hoping you might help me. What is the current solution to grab the UTM parameters and pass them into liquid variables to use as hidden fields in form submits? Thanks!
You can try looking at the request object, but I think that's just the URL (without params). Pre-2.0 Shopify didn't really support it, and Post-2.0 that hasn't changed. Using contentForQuerystring
is the only method I'm aware of. So, your only real option is to move the logic into the browser with some js running after the page loads.
There's also Storefront filtering on collection pages and search pages. Which might help you. It seems limited in what parms you can use, but might be enough for your use-case.
For now it's probably just best to stick to good ol' JavaScript:
const params = new URLSearchParams(window.location.search);
const value = params.get('email'); // ?email=test for example...
console.log(value);
contentForQuerystring
gets cached by Shopify. If you were to revisit the same page with a slightly different URL param value,contentForQuerystring
will give you the wrong (cached) param values.