Controller/template with child virtual page instead of route?

I have been trying to get an url pattern as much flexible as possble, but i can’t make it working all the time…

// URL e.g. some/page/template/id

    'pattern' => ['(:all)/(:any)'],
    'language' => '*',
    'action' => function($language,$place, $id){

   if($page = site()->find($place){
          if($page->template() == 'parent-place-template'){
               // generate virtual page with informations from $id
          }
   }
$this->next();
     }

i am thinking if that can also just be archived inside the template/controller, similar to passing a parameter or get request, however my attempt should still have a slug… not ?id=123, or id:123 but rather parent/123

is there any way to archive that within the controller. or any adjustment to the existing route (maybe there’s a better attempt)

if you want a dynamic slug using a route seems like the best option to me.

what exactly is not working?

to make it work in both multilang and single/no-lang setups you would need to check if id is null and then „shift“ the args - use place as id and language as place.

eventually i am progressing…

but can’t seem to properly access the $page variable after using site()->find($place)…

can’t directly access content(), and as well as need to use ->template()->name() to give an example.

    'pattern' => ['(:all)/(:any)'],
    'language' => '*',
    'action' => function($language, $place, $id){
        $site = site();
        $kirby = kirby();
        $param = params();
        if($page = site()->find($place)){

            dump($place);
            dump($page->title());
            dump($page->template());


  }
}

I can’t access the contents not directly though.

<?php foreach($data->features()->toStructure() as $feature): ?>
    <li class="inline px-2">
        <a href="<?= $data->url().DS.Str::slug($feature->keyword()->value()) ?>"> 
            <?= $feature->keyword() ?>
        </a>
    </li>
<?php endforeach ?>


// This outputs a List of URLS which are then accessable via the router...
/* Somehow it seems, not all slugs are working... and the router is not functioning on each entry in the structure.
The parent (e.g. $data->url() is always the same), the $feature->keyword() is always something like a city name or Job position... The slugs seem to be alright... 

Router:
*/
 'pattern' => ['(:all)/(:any)'],
    'language' => '*',
    'action' => function($language, $place, $id){
        $site = site();
        $kirby = kirby();
        if($page = site()->find($place)){
            $content = $page->content();
            foreach($content->features()->toStructure() as $feature){
                if(Str::slug($feature->keyword()) == $id){
                      // output any testdata
                }
            }
      }

// ...

A few work, many others do not trigger the route… even though the slug seems fine…

it seems, there have been a caching going on even though caching is unactive with the virtual page…