I’m trying to generate URLs for alternative template types (like .md instead of the default HTML) while preserving query parameters, and I’m wondering if there’s a cleaner way than manually constructing the URL.
Current approach
I’m building the URL manually like this:
$page->url() . '.md' . kirby()->request()->params()->toString(true)
This works, but I’m curious if there’s a more elegant method similar to how you can pass params to url():
$page->url(['params' => kirby()->request()->params()])
Question
Is there a built-in Kirby method to get a page URL with a different template type (like .md) that properly handles query parameters? I don’t see this documented anywhere — is there a recommended approach for linking to alternative template types?
Use case
I have a posts.md.php template that outputs markdown, and I want to link to it from the regular HTML posts.twig template while preserving any tag filters that might be active.
(As a sidenote, when query parameters are present, the resulting URL format is http://localhost:8000/posts.md/tag:Hello — which is a bit awkward format, in my opinion — not a blocker, just noting it.)
Any suggestions or workarounds would be appreciated!