CMS Development

Amit_95
Participant | Partenaire solutions Platinum
Participant | Partenaire solutions Platinum

Get current page URL slug

I want to get the slug from the current page. Do do this I'm using `{{ request.path }}`.

 

Currently, when executing `{{ request.path }}` it'll show me the slug as '/en/pro-test`. How can I get it so that it only shows me `/pro-test`?

0 Votes
6 Réponses
Jake_Lett
Guide | Partenaire solutions
Guide | Partenaire solutions

Get current page URL slug

If anyone is finding this on the google... this works {{content.slug}}

0 Votes
Indra
Guide | Partenaire solutions Elite
Guide | Partenaire solutions Elite

Get current page URL slug

@Amit_95 I don't know if you found your awnser, but to remove the ?hsLang=en, you can disable the 'Language Specific Redirects'.

You can check out the documentation at:
https://knowledge.hubspot.com/domains-and-urls/edit-a-domain-s-language-setting.

 

Let me know if this solutions works for you.


Vet Digital - The Growth Agency | HubSpot Solutions Partner Agency

Did my post solve your question? Help the community by marking it as a solution
0 Votes
jzilch
HubSpot Employee
HubSpot Employee

Get current page URL slug

Hi, 

 

Using {{ request.path }} will return the entire path from the URL. I would try and use the split filter found in the HubL docs here. https://designers.hubspot.com/docs/hubl/hubl-supported-filters. To split on the '/' and then return just the part of the URL that you want to use. 

0 Votes
Amit_95
Participant | Partenaire solutions Platinum
Participant | Partenaire solutions Platinum

Get current page URL slug

So `{{ request.path|split('/') }}`?

 

With this approach, it prints `/en/[en,%20pro-test]`

0 Votes
jzilch
HubSpot Employee
HubSpot Employee

Get current page URL slug

I would also set the second parameter of the split filter to display how many times it should split the URL. Also you will need to return the piece of the URL that you want to use. In this case you can use |last as the piece of the URL of the last item in your sequence. 

 

{{ request.path|split('/', 2)|last }}

Something like the above should work for you

0 Votes
Amit_95
Participant | Partenaire solutions Platinum
Participant | Partenaire solutions Platinum

Get current page URL slug

Ah, we're getting there!

 

That now spits out "pro-test". However, I have two translations of this page (English and French). I currently have ...

fr/{{ request.path|split('/', 2)|last }}

... added to the end of my domain, but it apends "?hsLang=en" to the URL (which results in a 404). Is there a way to remove the last bit too? It's not defined in my code so guessing it's HubSpot generated.

0 Votes