Valid url without folder in the panel

hi all,

i was searching with no success if it’s possible to have a valid url without creating the corresponding folder in the content folder.
For example:

c::set('routes', array(
  array(
    'pattern' => 'sitemap',
    'action'  => function() {
      return page('sitemap');
    }
  )
));

with a sitemap.php in the template folder,
so users don’t see an invisible useless “sitemap” page in the panel.

Yes, you can do that:

c::set('routes', array(
    array(
        'pattern' => 'sitemap',
        'action'  => function() {
          tpl::load(kirby()->roots()->templates() . DS . 'sitemap.php', array('uri' => $uri), false );
        }
    )
));

wow that was quick!
thanks.

working but i have an error on the page.
Can i access snippets and $site varibles when loading templates this way?

Oh yes, I guess the error stems from the header snippet, try this:

c::set('routes', array(
  array(
    'pattern' => 'sitemap',
    'action'  => function() {
      $page = page('sitemap');
      $site = kirby()->site();
      tpl::load(kirby()->roots()->templates() . DS . 'sitemap', array('page' => $page, 'site' => $site), false);
    }
  ),
));

And in sitemap.php pass the variables to the snippet:

snippet('header', array('page' => $page, 'site' => $site));
1 Like

working perfectly,
thanks very much!

is it posible to do so with the error template?
I mean removing the error folder and error.txt from the content folder,
and still redirect non existing urls to the error.php template.

thanks

Unfortunately not, the error folder must exist, otherwise Kirby throws an error.