Page to display users + user 'profile' pages

I can’t seem to find an answer anywhere, but I can’t be the first wanting to do that…

  • Is there a way to display a list of users in /users page ?
  • And link to a /users/johndoe ‘profile’ page ?
  • And (assuming we’ve stored an ‘author’ field in the posts), display this author’s posts ?

Any help appreciated…
Thanks !

To get the list of posts by a particular other, you can use the filterBy() method:

$user = "johndoe";
foreach(page('posts')->children()->filterBy('author', $user) as $page) {
  //do stuff
} ?>

If I understand you right, you have a custom /users page with the users as children of that page, so it’s the same procedure as for blog post, fetch the children of that page and display their information:

<?php foreach(page('users')->children() as $profile()) { 
//do stuff

Or do you mean panel users? Then you can get them like this:

$users = $site->users();
foreach($users as $user) {
  echo $user->firstname() . " " . $user->lastname();

Hi @texnixe
Thanks for your reply.
At the moment, I have no special ‘object’ on the site called users, appart from, well, (panel) users…
And I’d rather not duplicate the information (create a user object). Is there a way to list people that have an account on the site and display their name and avatar?
Following your advice, I managed to make have a list of my (panel) users on a /users page, but I can’t figure out how to have a ‘profile’ page for each of them (without duplicating the content)…

The second option ($site->users()) I posted above is then what you want. I was just irritated, because you mentioned a users folder with subfolders which does not exist in Kirby. You can find all about the $users/$user object in the cheatsheet.

Yes, I know the users folders don’t exist, but I don’t really understand how to generate a page like without duplicating the content.
At the moment, I have created a ‘users’ folder with a users.php template that lists all the users (using $site->users()). But now, how can each name link to a dedicated ‘profile’ page?
I can kind of see how I could do it by passing a parameter in the url like but it’s not very clean, is it?

Well, first of all, if you don’t want to create children of /users, you do not need the /users folder, you can use a route instead that calls the template.

And you can also use routes to create the dedicated profile pages.

Edit: Check out this thread for a possible solution: Single attachment page on kirby?

Thanks @texnixe!
Sounds like what I’m looking for…
I hadn’t thought about dedicated routing.