Skip to content

Instantly share code, notes, and snippets.

@gbrits
Created April 14, 2020 04:23
Show Gist options
  • Save gbrits/6dc2d72d2b63d0b278c7c1b16e5492f1 to your computer and use it in GitHub Desktop.
Save gbrits/6dc2d72d2b63d0b278c7c1b16e5492f1 to your computer and use it in GitHub Desktop.
Shopify $_GET variables via Liquid
<!-- 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 }}
@gbrits
Copy link
Author

gbrits commented Apr 30, 2024

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