What's your biggest current challenge? Have your say in Community Polls along the right column.

Re: How to get full current custom page url in liquid?

Solved

How to get full current custom page url in liquid?

nazimkeser121
Tourist
6 0 2

Hello Shopify exports,
I added new page called "support" on shopify store. ( For instance, url => store.website.com/pages/support ).
The page should be display the content of Vue app. I need to bind Vue app and liquid page.

For instance, if the url was "store.website.com/pages/support?123 and I wanted the entire URL, including the "?123".

This is custom page liquid code.

<vue-support  type="{{ url}}"> </vue-support>

{{ 'app.css' | asset_url | stylesheet_tag }}

{{ 'app.js' | asset_url | script_tag }}

<script>

var url = window.location.href;

</script>

As upi cam see from above liquid code, I need to bind "type" value with Vue app.

In script, I can get full url by window object. Then how can "url" variable bind with "type" attribue?

Best,

Nazim

Accepted Solutions (2)
Subhranil
Shopify Partner
41 8 56

This is an accepted solution.

Hello @nazimkeser121 
Use the following code to get the full URL path of any page-

{% assign full_url = request.host | append: request.path %}
{{ full_url }}


If helpful then please Like and Accept as a Solution.

 

View solution in original post

Morek
Shopify Partner
835 73 179

This is an accepted solution.

Hi @nazimkeser121 

Hope you're having a great day!

Full URL:

 

{%- 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 pageUrlWithHost = contentForQuerystring | split:'"pageurl":"' | last | split:'"' | first |
   replace:'\/','/' | 
   replace:'%20',' ' | 
   replace:'\u0026','&'
-%}
Full URL:  {{ pageUrlWithHost }}

 

 

URL without request-host:

 

{%- 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 pageUrlWithoutHost= contentForQuerystring | split:'"pageurl":"' | last | split:'"' | first | split:'.myshopify.com' | last |
   replace:'\/','/' | 
   replace:'%20',' ' | 
   replace:'\u0026','&'
-%}

Page URL without request host: {{ pageUrlWithoutHost }}

 

If you found this comment useful, hit the 'Like' and 'Accepted solution' buttons.

If you're looking for a Shopify developer or just want to connect, don't hesitate to reach out!
Portfolio: https://mmorek.com/
LinkedIn: https://www.linkedin.com/in/mmorek
WhatsApp: Whatsapp me!

View solution in original post

Replies 11 (11)

Morek
Shopify Partner
835 73 179

Hi @nazimkeser121 

Hope you're having a great day!

As specified here:

scrnli_7_24_2021_11-52-57 PM.png

If you found this comment useful, hit the 'Like' and 'Accepted solution' buttons.

If you're looking for a Shopify developer or just want to connect, don't hesitate to reach out!
Portfolio: https://mmorek.com/
LinkedIn: https://www.linkedin.com/in/mmorek
WhatsApp: Whatsapp me!
nazimkeser121
Tourist
6 0 2

Thanks for your reply.

I already used "request.path" but I can't get the param.

I want "https://store.com/pages/support?123
But I'm getting "pages/support" with "request.path".

Subhranil
Shopify Partner
41 8 56

This is an accepted solution.

Hello @nazimkeser121 
Use the following code to get the full URL path of any page-

{% assign full_url = request.host | append: request.path %}
{{ full_url }}


If helpful then please Like and Accept as a Solution.

 

nazimkeser121
Tourist
6 0 2

Thanks for your reply.

Seems I can't param with "request" object yet. ( I type url "store.website.com/pages/support?123" )

I'm getting "store.website.com/pages/support". I can't "?123" param.

 

If it's impossible in shopify, can I get it using javascript in liquid?
Please let me know the way.

Thanks.

it2
Visitor
3 0 0

 This has been so hard to get. copilot has no idea what I am talking about and now Im nervous adding anything but If I don't I am Invisible to every advertising agency and search engine.

it2
Visitor
3 0 0

your code has become infected. please add it fresh again sir

 

Morek
Shopify Partner
835 73 179

This is an accepted solution.

Hi @nazimkeser121 

Hope you're having a great day!

Full URL:

 

{%- 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 pageUrlWithHost = contentForQuerystring | split:'"pageurl":"' | last | split:'"' | first |
   replace:'\/','/' | 
   replace:'%20',' ' | 
   replace:'\u0026','&'
-%}
Full URL:  {{ pageUrlWithHost }}

 

 

URL without request-host:

 

{%- 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 pageUrlWithoutHost= contentForQuerystring | split:'"pageurl":"' | last | split:'"' | first | split:'.myshopify.com' | last |
   replace:'\/','/' | 
   replace:'%20',' ' | 
   replace:'\u0026','&'
-%}

Page URL without request host: {{ pageUrlWithoutHost }}

 

If you found this comment useful, hit the 'Like' and 'Accepted solution' buttons.

If you're looking for a Shopify developer or just want to connect, don't hesitate to reach out!
Portfolio: https://mmorek.com/
LinkedIn: https://www.linkedin.com/in/mmorek
WhatsApp: Whatsapp me!
nazimkeser121
Tourist
6 0 2

It helps to me.

Thank you.

StoneBridgeDigi
Shopify Partner
6 0 2

As of Aug 26 2023, the above code did not work correctly. However this code correctly provides the URL with query parameters:
{%- capture contentForQuerystring -%}{{ content_for_header }}{%- endcapture -%}
{%- assign parts = contentForQuerystring
| split: '"pageurl":"'
| last
| split: '"'
| first
| split: '://'
| last
| split: '/'
-%}
{% if parts.size > 1 %}
{%- assign domain_removed_parts = parts | slice: 1, parts.size -%}
{%- assign finalurl = domain_removed_parts | join: '/' | prepend: '/' -%}
{% else %}
{%- assign finalurl = "/" -%}
{% endif %}

{%- assign finalurl = finalurl
| replace: '\/', '/'
| replace: '%20', ' '
| replace: '\u0026', '&'
-%}

it2
Visitor
3 0 0

your code has become infected. Please re-upload

 

Asad-Mahmood
Trailblazer
224 40 45

@Morek 

Is there a way to store cookie value in shopify variable
using purely liquid not JS

this below is the cookie which i want to store

AsadMahmood_0-1734166388521.png

 

If my solution has been helpful, you can consider supporting me via Buy Me a Coffee.
Hire me: asadmahmood8470@gmail.com
WhatsApp