How to start the controller of a template with custom routes

Hi,

i have the following code in my custom route:

$data = array('devices' => $devices);
        tpl::$data = array_merge(tpl::$data, array(
            'kirby' => kirby(),
            'site'  => site(),
            'pages' => site()->children(),
        ), $data);
        echo tpl::load(kirby()->roots()->templates() . DS . 'comparison.detail.php');

Is there a posibility to run the controller of the template “comparison.detail” with this setup?

Yes. But you’ll need to construct a page object for it to work with, and that page will need to be using the comparison.detail template.

Controllers return data that goes to the template, so you need to include that in your array merge.

tpl::$data = array_merge(tpl::$data, array(
    'kirby' => kirby(),
    'site'  => site(),
    'pages' => site()->children(),
), $data, kirby()->controller($page, $data));
3 Likes