So I have a Plugin and create Virtual Pages and I use the following slug for one of the Pages: “account/login”. And I misconfigured a relative link that lead me to “account/account/login” I would expect a 404, but I got the Page. “account/account/account/login” etc. also works, and I wonder is that expected Behavior because I did not use the child and parent attributes? Is this a bug?
Maybe in your code, don’t know what you configured. Please provide more information.
This is some code from the plugin index file.
<?php
$pages["account/login"] = new Page([
"slug" => "account/login",
"template" => "login",
"translations" => [
"de" => [
"code" => "de",
"content" => [
"title" => "Login"
]
],
"en" => [
"code" => "en",
"content" => [
"title" => "Login"
]
],
],
"draft" => false,
]);
$pages["account"] = new Page([
"slug" => "account",
"template" => "account",
"translations" => [
"de" => [
"code" => "de",
"content" => [
"title" => "Konto"
]
],
"en" => [
"code" => "en",
"content" => [
"title" => "Account"
]
],
],
"draft" => false,
]);
Kirby::plugin("symcon/auth", [
"pages" => $pages,
"templates" => [
"login" => __DIR__ . "/templates/login.php",
"account" => __DIR__ . "/templates/account.php",
"licenses" => __DIR__ . "/templates/licenses.php",
"settings" => __DIR__ . "/templates/settings.php",
],
]);
This was just the first step i as I did not specify parent child relations yet.
This is not a valid slug, the slug is the name of the virtual folder, so not a path. A page must have a parent, either the site or an existing page.
Okay, so it should not have this behavior if I specify the relations?
So the account page should have the site as parent and the login page as child. And the login page should have the account page as parent?
So, adding “parent” => site()->page() to the configuration of the account page and temporarily removing the other pages should do the trick? Therefore, I should now only have one Page with the slug “account”. I can still access the Page over account/account/account and account should be a valid slug right?
Hm, yes, I can reproduce the issue. It probably happens because you cannot define a parent for the account page. Maybe add account
as page in the content, then add the login as child. Then it works. The parent
property only accept a page object as value, not the $site object.
So I found a workaround (Creating the Page as a Child of $site) as these Sites are not dynamic. It works, but I can only get one translation to work, so it just creates the de pages and not the en pages. So it seems to be a Problem with the Virtual Pages that are created within the Plugin Definition. It appears that the $site object does not hold them as children, while the Page itself has the site as Parent. I don’t know if this is relevant, but $site->children() seems not to hold virtual Pages at all.