Same template for different blueprints

The code from Kirby 2 won’t work for Kirby 3. You could, however, overwrite the template method for all those pages in their corresponding page models.

E.g. in the AlbumPage model, we want the page to load the note template instead:

<?php

class AlbumPage extends Page
{
    public function template()
    {  
        if ($this->template !== null) {
            return $this->template;
        }
        $intended = $this->kirby()->template('note');
        if ($intended->exists() === true) {
            return $this->template = $intended;
        }
        return $this->template = $this->kirby()->template('default');
    }
}

Alternatively, you could also overwrite the intendedTemplate() method, but I think I’d prefer the template method, then you can still use the intendedTemplate() for filtering purposes if needed.

1 Like