"Virtual" subpage possible with Kirby?

Hi there, hope you can help me with this. Let’s say I’ve the following setup and want to link every project page to a few subpages. Important is I don’t want to create the subpages manually for every project and the subpage1 shall be based on a subpage1.php template. The subpages shall get the same information as the project page above (e.g. $page->title()) It’s basically a “virtual” page. Does that make sense? Any idea how I can get this to work?

www.website.de/project-a
www.website.de/project-a/subpage1
www.website.de/project-a/subpage2

www.website.de/project-b
www.website.de/project-b/subpage1
www.website.de/project-b/subpage2

www.website.de/project-c
www.website.de/project-c/subpage1
www.website.de/project-c/subpage2

I’m not sure that I understand what the end goal is? If the subpage’s contain the same information as project-a page, what are they for? What is different about the subpages?

I think you could probably use routes to do it, but I have never used them myself, so i can only point you at the documentation.

Maybe I am not quite there with the idea. Think of the subpages as different versions of the project pages above. maybe just a different layout, the information will be different but “can” contain information from the project above.

basically I want the subpage to be a template but without creating it manually for every project page.

But if the information is different on the subpages (apart from some bits), then you will need to create a page to store the content that is different. So you will need to do it manually, i think.

There isn’t really new information necessary on the subpages. The most simple way to think of would be the subpages have just another layout/theme then the project page above and therefore need another php. I might be able to change the layout with some javascript but would like to go for some template php solution. Sorry maybe my idea is to complicated :frowning:

It’s ok, the more information you provide, the better the answers will get :slight_smile:

It sounds to me like what you are really talking about is art directed pages. Kirby is capable of loading stylesheets and javascript based on templates, which means you can get it to automatically add new code just for that page (based on the template). This is described here and here. You can also add the code to the pages folder, if you literally just wanted it on that specific page.

In terms of rearranging the page, for different layouts, it might be worth considering the Modules plugin, because this allows you to break the page down into “lego bricks” that can be added and arranged in the panel.

Routes would be the way to go. You can use tpl::load() to load a specific template. Of course, you would have to create the template but not the subpages. You can even pass additional data to that template.

The downside is that you need to pass the $kirby, $site and $page objects to each template and pass these variables down to each snippet used in the templates.

I was able to get it working with Routes as I imagined :blush: thank you both!

c::set('routes', array(
      array(
        'pattern' => '(:any)/subpage',
        'action'  => function($uid) {
    	  $page = page($uid);
          site()->visit('/' . $uid);

          tpl::$data = array_merge(tpl::$data, array(
            'kirby' => kirby(),
            'site'  => site(),
            'pages' => pages(),
            'page'  => page()
          ), $page->templateData());

          echo tpl::load(kirby()->roots()->templates() . DS . 'subpage.php');
          return false;
        }
      )
    ));