Hey there.
I allready found help in this entry:
Continuing the discussion from Building user profile pages in Kirby 3:
In the model I added fields like addresses and links, but how do I get images, that were uploaded in the user account?
<?php
class RaeumePage extends Page
{
public function children()
{
$usersPages = [];
$users = kirby()->users();
foreach ($users as $key => $user) {
$userPages[] = [
'slug' => Str::slug($user->id()), // or username if unique
'num' => $user->indexOf($users),
'template' => 'user',
'model' => 'user',
'content' => [
...
'avatar' => $user->avatar(),
'image' => $user->image(),
...
]
These fields are files
^^ one or many
When I want to call them in the template, I get no content.
<?php if($avatar = $page->avatar()): ?>
<img src="<?= $avatar() ?>" alt="">
<?php endif ?>
<?php foreach ($page->image() as $image): ?>
<img src="<?= $image() ?>" alt="">
<?php endforeach; ?>
I am allways losing trake about the format of the field. Is $user->image()
an object or do I need to convert ->toFile()
or ->toFiles()
somewhere?
Or do I need to manipulate the route somehow to get the images?
config:
<?php
return [
'routes' => [
[
'pattern' => 'user/(:any)',
'language' => 'de',
'action' => function($user) {
$site = kirby()->site()->find("raume");
return tpl::load(kirby()->roots()->templates() . DS . 'user.php', array('user' => $user, 'site' => $site), false);
}
]
],
'debug' => true,
'languages' => true,
];
I highly appreciate your support.
Thanks in advance.