This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

lockzackary7643
lockzackary7643

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

asbig
asbig

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>
lockzackary7643
lockzackary7643

ah great, thanks a lot. i used {{ this.page.baseFileName|app }} and got what i needed.

Kirill Artemenko
Kirill Artemenko

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

ctrlaltdylan
ctrlaltdylan

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:

{{ this.page.id }}

I think you may have meant:

<a href="{{ page.id | page }}">{{ page.id }}</a>
Maria VilarĂ³
Maria VilarĂ³

What if I need to do this in the component code and not on the template?

beaudinngreve10852
beaudinngreve10852

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.

dev.mnr.j20762
dev.mnr.j20762

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!!!

abass
abass

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

endi.linux.mint51510
endi.linux.mint51510

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

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.