Create a dynamic page

Is is possible to create a dynamic page with an plugin?

Example:
I have a page /blabla. And now I would like create a pdf version of this page with the url /blabla/pdf. I don’t like to create for every page a sub page. I think one part is to create a pattern in the config, correct? But how can a create a really dynamic webpage in kirby?

Need I create a /pdf page and redirect the pattern (:all)/pdf to the page with the placeholder in the url parameter (/pdf?page=blabla)?

Has some one a hint for me, to create this?

So, couple of questions you need to know the answer to before you begin:

  1. Should any page be downloadable as a pdf, or only a subset of pages?
  2. If it’s a subset of pages, then what do these have in common? Are they all descendants of one common page? Do they all use the same template?

I love the kirby router. However, a controller may also be valuable in this instance. If all of the pdf downloads happen on the same template, then you could use a controller to trigger them (eg. uri/to/page?dl=pdf). If it’s something that goes across multiple templates then a custom route is the way to go.

Probably not. Routes can respond with absolutely anything you want them to, including a pdf download.

Oh, and I forgot to answer this section: yes. Routes don’t have to be in the config, they can happily exist within a plugin. Just be aware that if you place routes in plugins, it’s less obvious when you have conflicting routes since they may be spread across different files.

Eg. in site/plugins/routing/routing.php:

kirby()->routes(array(
    array(
        'pattern' => 'routing',
        'action'  => function() {
            return response::json(array(
                'look', 'ma,', 'no', 'hands!'
            ));
        }
    )
));

Sorry for the missing information. It should be a solution to generate a pdf for every page (later with right management).

Thanks for your answers.