I am working on a multi-language website and have to manually build url()
for some links.
I tried to use this syntax to build the first part of the URL
$site->index()->filterBy('template', 'template-name')
but the result I get is null
.
I realised it is because what I get is a collection of pages, but is it possible to only extract its uri
or slug
?
texnixe
February 20, 2017, 6:08pm
2
A collection does not have a URL, what exactly are you trying to do?
UPDATE, found a simple solution even though it is semantically hacky? I just added ->first()
as the collection with that template
only has one page and several subpages.
$places = $site->children()->filterBy('template', 'places')->first();
<a href="<?php echo $places->url() . '/' . str::slug($page->location()->html()) ?>">
In this way also the url is automatically translated into the two languages.
1 Like
texnixe
February 20, 2017, 6:36pm
4
BTW: findBy()
returns a single page.
$places = $site->children()->findBy('template', 'places');
1 Like
Great! Even better, I thought that should have been an easier simpler command.