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`?
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`?
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. Accounts Dashboard | HubSpot. To split on the ‘/’ and then return just the part of the URL that you want to use.
So `{{ request.path|split(‘/’) }}`?
With this approach, it prints `/en/[en,%20pro-test]`
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
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.
@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:
Manage domain language settings.
Let me know if this solutions works for you.
If anyone is finding this on the google… this works {{content.slug}}