Sitemaps easiest way

An old thread now but I just tested it and I like how it looks for most part.

Why sitemap as content page?

However I don’t like to create a content page just for it to show up on the site. We are not adding any content to it in the panel (in this example).

Route it

I solved it, almost “by the book” but with one different thing. I load a template directly from the route. Then I don’t need to create content I don’t need.

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

Minor fix to the template

I use this template for it:

http://getkirby.com/blog/xmlsitemap

A minor problem is that $page is unknown because the template is called directly from the route. It’s easily fixed by adding this row on line 2.

$pages = site()->pages();