Path to the first child page?
Permalink
Can someone please tell me how to programatically get the path to the first child page, to use that code in a custom block to create a link for an element of that block (image)?
I don't want to redirect the page, I just need the path to link an image of a custom block ( in view.php) to the first child page. If no child page exists, nothing should be output.
In other words: clicking on an image in a custom block should lead to the first child page.
How could that be done?
I don't want to redirect the page, I just need the path to link an image of a custom block ( in view.php) to the first child page. If no child page exists, nothing should be output.
In other words: clicking on an image in a custom block should lead to the first child page.
How could that be done?
I guess something like:
Thanks, but the problem is, we have to get the ID first.
The custom block should get it by itself.
To be more precise: I have built a custom image block. The image displayed by this block should be linked to the first subpage of the page where the block is inserted.
The snippet I'm looking for would have to recognize the current page ID, the page ID of the first subpage and finally the path to the first subpage.
The custom block should get it by itself.
To be more precise: I have built a custom image block. The image displayed by this block should be linked to the first subpage of the page where the block is inserted.
The snippet I'm looking for would have to recognize the current page ID, the page ID of the first subpage and finally the path to the first subpage.
You should find what you need in this page
https://www.webli.us/cheatsheet/doku.php...
https://www.webli.us/cheatsheet/doku.php...
$page = Page::getCurrentPage(); $pageID = $page->getCollectionID();
Then instead of adding 21 above, you can add $pageID
Thank you very much for your help @madesimplemedia and @ConcreteOwl!
That code works fine, except if the block is placed on the start page (since then there is no parent page).
Could there be a solution?
That code works fine, except if the block is placed on the start page (since then there is no parent page).
Could there be a solution?
Would you want to hide the block in this case, or what?
No, the block should simply behave the same on the start page as on any other page: the image should point to the first subpage. Otherwise that block can only be used to a limited extent, which means that it would be easier to make the image link manually selectable.