Kriuchko
12/14/2018 - 12:00 PM

GET variable in url custom parse url

Shopify variables in url parse url


{%- comment -%}

  Liquid by Jason @ freakdesign.
  Questions? Ping me on twitter: @freakdesign

  Relates to blog post:
  http://freakdesign.com.au/blogs/news/get-the-url-querystring-values-with-liquid-in-shopify

  Example:
  https://jasons-experiments.myshopify.com/collections/all/products/3-4-sleeve-kimono-dress-coral-1?ref=freakdesign&cache=false

{%- endcomment -%}

{%- comment -%} Capture the content for header containing the tracking data {%- endcomment -%}
{%- capture contentForQuerystring -%}{{ content_for_header }}{%- endcapture -%}

{% comment %} Use string splitting to pull the value from content_for_header and apply some string clean up {% endcomment %}
{%- assign pageUrl = contentForQuerystring | split:'"pageurl":"' | last | split:'"' | first | split:'.myshopify.com' | last |
   replace:'\/','/' |
   replace:'%20',' ' |
   replace:'\u0026','&'
-%}

{%- for i in (1..1) -%}
  {%- comment -%} If the string doesn't contain a ? then we have no querystring. Go no further {%- endcomment -%}
  {%- unless pageUrl contains "?" -%}{% break %}{%- endunless -%}

  {%- comment -%} Only work when the cache qs is used. Be aware of the perf issues with using cache=false {%- endcomment -%}
  {%- unless pageUrl contains "cache=false" -%}{% break %}{%- endunless -%}

  {%- comment -%} Split the url at the ? to get all values after it {%- endcomment -%}
  {%- assign pageQuerystring = pageUrl | split:'?' | last -%}

  {%- comment -%} Split the remaining string at & to get the list of keys and values (if any) {%- endcomment -%}
  {%- assign parts = pageQuerystring | split:'&' -%}

  {%- comment -%} Loop over them... {%- endcomment -%}
  {%- for part in parts -%}

    {%- comment -%} Split the part at the =. Not all querystrings will be in pairs so we need to account for that {%- endcomment -%}
    {%- assign keyAndValue = part | split:'=' -%}

    {%- if keyAndValue.size > 1 -%}

    key: {{ keyAndValue[0] }}
    value: {{ keyAndValue[1] }}

    {%- endif -%}

  {%- endfor -%}
{%- endfor -%}

--------- колллекции ---------

https://help.shopify.com/themes/customization/collections/add-view-all-to-collection-pages

это, по сути, GET 
collection.15.liquid
collection.10.liquid
но только через ?view= надо передавать цифру