Check for / fetch multiple templates with if($page->template() == 'about‘)

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!


You can use an or statement

<?php if($page->template() == 'about' OR $page->template() == 'default' OR $page->template() == 'gallery'): ?>

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 ORs:

$templates = ['exhibition', 'book', 'news-items'];
if(in_array($page->template(), $templates)): ?>
  <?php echo js('assets/js/nav+slideshow.min.js') ?>
<?php endif ?>

Still works with Kirby 3. Great!