Possible to use template in a route without a file in /content?

I would like to set up a route that renders “data” fetched in the route (or in a controller) but without polluting the content folder with an empty content/{foldername}/template.md.

I’m not sure if this is clear; let me elaborate. I have this, and it works:

I have:

  • in /content I have a directory “bar” which has an empty demo.md file in it
  • a demo template which simply echoes $foo
  • following route in my /site/config/config.php

c::set('routes', array(
array(
    'pattern' => '(:any)/foo/(:any)',
    'action'  => function($lang, $param) {
        site()->visit('bar', $lang);
        $page = page('bar');

        $data = array(
            'foo' => $param
        );

        return array('bar', $data);
    }
)
));

Now on to the question: is there a way to achieve the same, but without the necessity of the “bar” folder in /content ?

Thanks!

Yes, you can load a template in your route, using tpl::load()

Faster then lightning :wink:

Unfortunately the docs are a bit scarce. Can you eloborate a bit?

Thx!

I have to leave now, but if you use forum search, you will find examples.

https://forum.getkirby.com/search?q=tpl%3A%3Aload

1 Like

Did the links help or do you need more information? If everything is fine, could you please mark this as solved? Thanks!

Solved, sorry.

Thanks for the help.