Hello,
I use this code in my footer to use some css and js on differents templates, It works this way but I think it is not the good one…
<?php if($page->isHomepage()): ?>
<?php echo css('assets/light-box/light-box.css') ?>
<?php endif ?>
<?php if($page->isCollection()): ?>
<?php echo css('assets/light-box/light-box.css') ?>
<?php endif ?>
How can I write it better ?
Thank you.
If the special CSS file is the same for every template you need to cover, you can use a logic OR to use the same code if one or more of the conditions are true:
<?php if($page->isHomepage() || $page->isCollection()): ?>
<?php echo css('assets/light-box/light-box.css') ?>
<?php endif ?>
Thank you Lacasbestle,
I already tried this way, but css and js are displayed in every page of website, not only on Home and Collection template.
Yes code needed is exactly the same for the 2 pages.
What is the isCollection
method you use? Is it a method defined in a Page model or a field in the content file?
Collection is just a Template of page.
(Sorry very newbie with php and Kirby)
Then you should check for the template:
if($page->template() == "collection") { //do stuff; }
I’ll do it this way, thank you 