Created
April 14, 2020 04:23
-
-
Save gbrits/6dc2d72d2b63d0b278c7c1b16e5492f1 to your computer and use it in GitHub Desktop.
Shopify $_GET variables via Liquid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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 }} |
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);
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.