Show content if a page has a certain tag

Hi,

I want to display some content if “Kirby” is one of the page tags. Below code only works if “Kirby” is the only tag. Really appreciate the help!

<?php if ($page->compatibleWith()->value() === 'Kirby'): ?>

<?php endif ?>

One way would be splitting the value into an array (by default the ->split() method splits the value at each , - which is also the default separator for the tags field). And then checking if your value 'Kirby' is inside that array.

<?php if (in_array('Kirby', $page->compatibleWith()->split()) === true): ?>
1 Like

Awesome, that worked! Thanks!

1 Like