Render a template without the corresponding content

Displaying external data is fine and we will see better options for that in Kirby 3, because we won’t have the strong tie between the file system and page anymore.

But we are still with Kirby 2 for the moment…

As I said, you can pass the Kirby and Site objects to your template, but you will not have a page object. That will presumably cause issues in your standard header and footer snippets, where you usually call the page as well, for example to display a meta title tag.

But let’s get to the template stuff first:

$kirby->routes(array(
    array(
      'pattern' => 'collection/(:any)',
      'action' => function($collectionHandle) {
       return  tpl::load(kirby()->roots()->templates() . DS . 'template.php', ['kirby' => kirby(), 'site' => kirby()->site()], false );
      }
    )
  )); 

If you use any snippets in the template and these snippets also use these variables, you have to pass them down to the snippets as well, for example.

snippet('header', ['kirby' => $kirby, 'site' => $site]);

Since you don’t have a page object, you have to use an if-statement in your template/snippets wherever you call a page method and display information from your external source instead.

A single dummy page folder would nevertheless make your life easier…

1 Like