Unfortunately I need to link from other pages (infos.php) to “gegenseiten”. But I can’t figure out how to wright the php.
<?= $info->url() ?>
Gives me an error of “Undefined variable: info”.
I guess, because the content of “gegenseiten” is filled by different snippets the url has to be generated diffently tha with “->url()”.
Also I would like to somehow link to the listing page “infos” which content also gets generated by these snippets.
Must I use a route and go down the routes route?
Only the ancestor gegenseite? In that case you could use
<?= $page->parents()->last()->url() ?>
From where? From a child page? From anywhere?
You can always link to a page with the page helper and the full path:
<?php if ($infoPage = page('uber/infos')) { echo $infoPage->url(); } ?>
Or you can link to a parent page, e.g. if you are on an infos subpage and want to link to the listing (which is the parent):
<?= $page->parent()->url() ?>
This
<?= $page->parents()->last()->url() ?>
works fine for me.
But I need to also link from the snippets for “gegenseite” to the lists of all infos, news and gotchas.
So I tried
<?= $page->children()->last()->url() ?>
which of course gives me the last. Then I tried without “last”, but then it doesn’t know which one and gives me nothing, not even an error.
So I tried:
<?php if ($infoPage = page('uber/infos')) { echo $infoPage->url(); } ?>
but this gives me of course only that 1 page. So I tried something like this:
<?php if ($infoPage = page('uber/infos')) { echo $infoPage->url(); } ?>
<?php elseif ($infoPage = page('freenow/infos')) { echo $infoPage->url(); } ?>
<?php elseif ($infoPage = page('clevershuttle/infos')) { echo $infoPage->url(); } ?>
<?php endif ?>
hoping I would do my first if/else thing right, but no.
Also just using “else” resulted in errors of the unexpected kind (end of file).
How, I mean what is the right way to do this.
Almost there!
<?= $page->children()->first()->url() ?>
seems to be the right choise!
Except for the title.
<?= $page->children()->first()->title() ?>
doesn’t give me the title.
But this does:
<?= $page->title()->html() ?>
and this:
<?= $page->title() ?>
stupid me. Sorry.
This works because a page always have a title.
This only works if children (subpages) for the current page exist. This isn’t always true and depends on your site’s structure.