Dan
1
Hi, is it possible to fetch multiple templates?
This works only with one template:
<?php if($page->template() == 'about'): ?>
What I need is something like:
<?php if($page->template() == 'about', 'default', 'gallery'): ?>
Thanks for help!
Dan
texnixe
2
You can use an or
statement
<?php if($page->template() == 'about' OR $page->template() == 'default' OR $page->template() == 'gallery'): ?>
3 Likes
Dan
3
Ha thanks a lot, I had tried the following code before:
<?php if($page->template() == 'impressum' || $page->template() == 'profil' || $page->template() == 'gallery'): ?>
This did not work! But it works yet (but I prefer OR). I had a spelling error in the template name. Ufff.
For anyone else stumbling upon this useful answer, there is a missing )
at the end of the line, before :
So it’s for example like:
<?php if($page->template() == 'exhibition' OR $page->template() == 'book' OR $page->template() == 'news-item'): ?>
<?php echo js('assets/js/nav+slideshow.min.js') ?>
<?php endif ?>
Furthermore, how would you use the new syntax not in
(introduced in kirby 2.3.2) in the if statement
?
It says to make an array…
Here’s a shorter way to achieve the same without all the OR
s:
<?php
$templates = ['exhibition', 'book', 'news-items'];
if(in_array($page->template(), $templates)): ?>
<?php echo js('assets/js/nav+slideshow.min.js') ?>
<?php endif ?>
5 Likes
Still works with Kirby 3. Great!