Is there a way to use page() and specify which representation you want?
More specifically, if I had a /sitemap page and it has sitemap.txt and sitemap.xml.txt within it, is it possible to specify which representation I want to return in a Kirby Route?
Aside from redirection, it’s unclear to me how I could map something like example.com/foo-bar-sitemap.xml to actually show content from example.com/sitemap.xml. Similar problem for other representations like json api representations.
Kirby has a built-in way to provide your page(s) content using custom representations - there is a section about it in the ‘advanced’ area of the docs.
That’s the mechanism I’m using to actually handle the representation types when accessed from a browser’s standpoint.
What is unclear to me is how I can access those representations from a code standpoint.
Perhaps I want to display a list of alternative representations, or, like in my original example, re-map a URL to show content from some other page’s alternative representation.
You would probably just create them either in your page controller, or page model - e.g., you would create an as_xml() or as_json() method that simply returns the page data you need in the appropriate format.
If there is a template for that representation, you could also load the template in routes (using tpl::load). But that only makes sense if you need that template for other purposes. Other than that, I’d also use methods that return your content in the appropriate format as already suggested by @luxlogica. You can also do things like this: