Hi.
I’m using subpages to integrate content into the main page. The subpage itself doesn’t have a template on its own.
It’s working fine.
- width: 1/1
sections:
references:
label: References
type: pages
template: reference
What I wanted to ask: As far as I can tell, the subpages need to be unlisted or listed In order to be accessible on the main page. But in both states the subpages are available trough a URL, which when called only shows the page title as defined in the default template of the starter kit.
Is there a way to either redirect all traffic that tries to access the subpage to the master page or a way to integrate the subpages without publishing? Or is wrong or bad style to do this at all?
Your best bet is to create a route to redirect all subpages to the parent page:
Theoretically possible but imo not such a good idea, after all, publishing allows you to definitely say “this is ready to go online” and only published pages are validated (e.g. required fields, field values).
No, it’s totally fine to do it like that.
There’s also a plugin that makes handling such modules a bit easier:
Thanks Sonja for the support.
The part with the routes is tough. To be honest, I’m only understanding half of what is written there and it just doesn’t feel good using something I don’t fully understand.
Especially when it comes to the Multi-language setup. The URLs are language specific and the subpages are not containing a keyword that could be used for a pattern. Maybe I’m missing something here, but as I said… this seems to be nothing for beginners.
The plugin is nice, but looks as if I would have to rebuild everything to be based on modules. Plus, plugins are somehow black-boxes for me. The reason I opted for Kirby is to learn and understand how things are working.
Maybe its just to late and I should look at it tomorrow with a fresh head.
Thank You. Have a nice evening.
Best
Marc
That doesn’t matter in this case because you can use a placeholder to catch all subpages:
'routes' => [
[
'pattern' => 'parentpageslug/(:any)',
'action' => function ($slug) {
return go('parentpageslug');
}
]
]
OK. And ‘parentpageslug’ needs to be replaced by the name of the parent page? The Parent name is also called differently in each language.
By the slug of the parent page, yes. e.g. if your page is called blog
the pattern would be
'pattern' => 'blog/(:any)',
'language' => '*'
Setting the language to *
should fetch the right pattern in all languages.
If that doesn’t work, let me know and I’ll look into it tomorrow.
Working!
Many thanks. I can say I learned something today.
One more question on this topic. If called by the URL, the subpages are now redirecting to the parent. In the parent, I have anchors for the subpages.
Is it possible to redirect from the URL to the anchor? Probably not when using (:any) right?
I would expect something like
'routes' => [
[
'pattern' => 'blog/(:any)',
'language' => '*',
'action' => function ($slug) {
return go('blog/#' . $slug);
}
]
]
to work.
Unfortunately, this doesn’t work.
[
'pattern' => 'references/(:any)',
'language' => '*',
'action' => function ($slug) {
return go('references/#' . $slug);
}
]
is calling the following URL → http://localhost:8081/de/references#de
Ah, sorry, forgot that the language is the first argument:
[
'pattern' => 'references/(:any)',
'language' => '*',
'action' => function ($language, $slug) {
return go('references/#' . $slug);
}
]