Hey guys, i’m trying to figure out if something like
<?= $site->children()->template('cases')->url()?>
works? In this case it doesn’t work. I build a one pager (One-pager | Kirby CMS) and i want to be sure if someone changes the url or name of a page that the snippets are shown correctly. Because nobody can change the template for the snippets it is the safest option but every snippet is shown by its section id (<section id="cases">) so it has to be dynamically.
It is best if you use something that can’t be changed for the snippets, e.g. the intended template rather than the UID. Or a name in a field that can’t be changed.
$page->template() doesn’t take an argument and it only returns a string, i.e. the name of the template. I’m not sure what you are trying to do here. A page object has an url method, or a file.
Do you want to echo the URL of a page with a given template?
The easiest way is the to filter by template, then loop through the collection (instead of looping through all and then use an if statement to check for the template):
Okay thank you very much! Got it to work right now. I changed the ID from uid to template and your foreach loop helps me when i use href on a button e.g. from main page snippet cases.php where only 6 cases are shown to template cases.php where all cases are shown. Again, thank you very much! Saved my life