eventsByUser
is a site method extension that needs the user id (e.g. 3fLVe49j
)
In the user blueprint I’m trying to pass that parameter with user.id
but I can’t seem to get the syntax right.
# site/blueprints/users/attendee.yml
userEvents:
label: Events attended by the user
type: info
text: '{{site.eventsByUser( {{ user.id }} )}}'
# this works fine
# text: '{{site.eventsByUser(3fLVe49j)}}'
Clues?
1 Like
That won’t work, because user.id
is not evaluated, see this post Sharing files between pages & linking them via 'pages' field also for alternatives.
Sounds great for pages, but can I do that with a user?
I guess I can’t extend the user object by adding a method or something similar, or…
You are right, you can’t yet. But that would be the way to go. Here is the idea issue for it: https://github.com/getkirby/ideas/issues/229 - make sure to put your +1 on it
But if you only want to show all events by the current user, you don’t have to pass an argument at all and you don’t need a custom user method?
Kirby::plugin('my/plugin', [
'siteMethods' => [
'eventsByUser' => function () {
if($user = kirby()->user()) {
$event = page('events')->children()->filterBy('user', $user->id());
} else {
$events = new Pages();
}
return $events;
}
]
]
It’s not by the current logged user, but in the panel the currently open user page.
that’s why I was trying to use:
text: '{{user.id}}'