Hi,
I have a set of Kirby users, and would like to show their profiles as pages on the front end of the website. I have a listing page (/creators
) that I would like to be the parent of these pages. So for the child pages I would like to have /creators/user-name-uuid
as the url.
What is the best way to approach this? Is it a route using virtual pages, or is there a better way?
Also, I am guessing I will need to include the uuid of the user in the url to avoid issues with people with the same name, is there any security implication to doing this?
Thanks for your thoughts!
No, not a route, but a model for the creators page where you define the user profiles as children
Great, thanks for the pointer.
This is what I have landed with:
<?php
use Kirby\Uuid\Uuid;
class CreatorsPage extends Kirby\Cms\Page
{
public function children(): Pages
{
if ($this->children instanceof Pages) {
return $this->children;
}
$creators = [];
foreach (kirby()->users()->filterBy('role','member') as $creator) {
$creators[] = [
'slug' => Str::slug($creator->profileName()) . '-' . $creator->uuid()->id(),
'num' => 0,
'template' => 'creator',
'model' => 'creator',
'content' => [
'title' => $creator->profileName(),
'uuid' => $creator->uuid()->id(),
]
];
}
return $this->children = Pages::factory($creators, $this);
}
}
Which does the job of setting up the urls as I would like, and also passing the uuid from the user as part of the content means I can find all the rest of the user data on the individual creator page like this:
<?php
$creator = $kirby->users()->find($page->uuid()->id())
?>
Super simple and works a treat.
I Kirby sometimes
1 Like