Only run hook for specific templates

Hello guys it’s your favorite noob back with another problem;

I would only like this hook to run for my specific pages, in my case if its using the “car” or “van” template, otherwise the hook will return errors when editing other pages

Kirby::plugin('pluginname', [
    'hooks' => [
        'page.update:after' => function ($newPage, $oldPage) {
            if ($oldPage->Template() === 'car' || 'van') {
                // hook stuff here

This is what I’ve got, but it appears to be breaking my API that is running in the hook.

thanks - Josh

You can do this like that:

if (in_array($oldPage->intendedTemplate()->name(), ['car', 'van'])) {
  // hook stuff here
1 Like