URL Parameters in LIQUID?

Nisarg
Shopify Partner
26 5 9

@Caroline_Schnap  I do not know if this is the right way to do this but I am getting URL with the parameter using following liquid code : 

{% assign pageurl = content_for_header| split:'"pageurl":"' | last | split:'"' | first %}

@sydsfaisal  you can try this.

Papas_Pringles
Shopify Partner
24 0 5

Nisarg, can you please provide an example of where or how you used this code?  I'm having trouble visualizing it in my code.

0 Likes
Nisarg
Shopify Partner
26 5 9

@Papas_Pringles content_for_header is a global liquid object which contains header related common tags. In which there is a parameter pageurl which have the page URL and its parameter in it. Above mention code extract that page URL content from content_for_header object. So now after above line if you print {{ pageurl }} than it will print the URL which is hit with the parameter.

Just include the above mention code in your liquid code and try to use it. If you want to fetch parameter values from that variable than it requires some liquid filters on pageurl. Do let me know if you want that let me know, I will do the coding and let you know.

 

0 Likes
IconStudios
New Member
2 0 0

This works but... 

content_for_header Is saved with browser cache and it wont work how you want it to...

For example, your URL and query looks like this: store.myshopify.com/?param=value1

When you try again with store.myshopify.com/?param=value2 you will still get value1 due to the saved cache

0 Likes
Lucaspw
New Member
3 0 0

are you sure? I test it and each refresh I have other url params, never cache

0 Likes
MJaspan
Shopify Partner
16 1 0

Hi @Caroline_Schnap, can you please tell me if URL Parameters have been added as described here? If not, can you please add me to the list?

0 Likes
MJaspan
Shopify Partner
16 1 0

Here is a real server-


@sydsfaisal wrote:

hi 

is there any luck for this issue ?? help i have same issue 

 



side solution: https://freakdesign.com.au/blogs/news/get-the-url-querystring-values-with-liquid-in-shopify

0 Likes
attotasolutions
Shopify Partner
12 0 5

Hi,

You can get value of page from the URL https://www.mydomain.com/mypage?page=3 using the below code.

{%- capture contentForQuerystring -%}{{ content_for_header }}{%- endcapture -%}
{%- assign page_url = contentForQuerystring | split:'"pageurl":"' | last | split:'"' | first | split:'.myshopify.com' | last |   replace:'\/','/' |    replace:'%20',' ' |    replace:'\u0026','&'  -%}
{%- assign param_page = '' -%}
{%- for i in (1..1) -%}
	{%- unless page_url contains "?" -%}{% break %}{%- endunless -%}
	{%- assign query_string = page_url | split:'?' | last -%}
	{%- assign qry_parts= query_string | split:'&' -%}
	{%- for part in qry_parts -%}
		{%- assign key_and_value = part | split:'=' -%}
		{%- if key_and_value.size > 1 -%}
			{% if key_and_value[0] == 'page' %}
				{%- assign param_page = key_and_value[1] -%}
			{% endif%}
		{%- endif -%}
	{%- endfor -%}
{%- endfor -%}

Page value = {{ param_page }}

 

Hope this helps other developers.

What I have done to solve the cache issue is to provide a dummy `sort_by=` query string. I noticed the cache always clears when you update its value. 

{% assign pageurl = content_for_header | split:'"pageurl":"' | last | split:'"' | first %} 

 

Use like this:

http://my-store.myshopify.com/pages/about?sort_by=fake

KondaSoft.com - Premium and Free Shopify Themes
0 Likes