This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
I have a page set up with
title = "Directory"
url = "/directory/:filter_slug?/:filter_id?"
[directory]
entry_page = "politician"
filter_slug = "{{ :filter_slug }}"
filter_id = "{{ :filter_id }}"
The component generates a page containing links to other directories (that uses the same component) depending on the provided filter_slug
and filter_id
, so the links displayed on the page /directory
works as expected. Problem is the links displayed when a slug and id is provided becomes/directory/slug/id/slug/id
Using {{ url_current() }}
returns the current url as seen on the browser's address bar. If a component is set up on a page on the CMS with optional parameters on its URL, is there any way to retrieve only the base URL of the page?
Last updated
I'm not sure if this is exactly what you looking for but have you tried using reverse routing.
Then you can have something like this in you page markup:
<a href="{{ this.page.id | page }}">{{ this.page.id }}</a>
ah great, thanks a lot.
i used {{ this.page.baseFileName|app }}
and got what i needed.
Hope it help:
<a href="{{ ''| page }}">Current page with current filter slugs</a>
<a href="{{ ''| page(false) }}">Current page without any filter slugs (except default value)</a>
<a href="{{ ''| page({ filter_slug:slug_var, filter_id:id_var }) }}">Current page with needle filter slugs</a>
Last updated
asbig said:
I'm not sure if this is exactly what you looking for but have you tried using reverse routing.
Then you can have something like this in you page markup:
I think you may have meant:
<a href="{{ page.id | page }}">{{ page.id }}</a>
maria.vilaro19086 said:
What if I need to do this in the component code and not on the template?
Hey you can use
$this->currentPageUrl()
This returns the current page URL with supplied parameters and route persistence.
Kirill Artemenko said:
Hope it help:
<a href="{{ ''| page }}">Current page with current filter slugs</a> <a href="{{ ''| page(false) }}">Current page without any filter slugs (except default value)</a> <a href="{{ ''| page({ filter_slug:slug_var, filter_id:id_var }) }}">Current page with needle filter slugs</a>
Thanks!!!
How would I echo out just the directory of the URL?
Example, we are on the page ABC Corp (https://website.com/abc-corp) and I want to just echo out "abc-corp" from the URL? So everything after the /
I can't seem to figure out how to do that.
Thanks so much!
UPDATE:
Just use {{ this.page.baseFileName }}
without the | app
-- Beautiful!
Last updated
I don't know if this accurately describes what is being discussed here. But I tried {{ this.controller.currentPageUrl() }} to get the current page. I've tested it using https://validator.schema.org/ and it's exactly what I wanted.
Using {{ this.page.baseFileName }} will return https://yourwebsite.com/folderPage/link instead of https://yourwebsite.com/link.
Last updated
1-10 of 10