Change outout in Blueprint "type: user"

Hi guys,

i’m using the Author Selector in a blueprint:

Autor:
    label: Autor
    type: user
    default: user
    width: 1-2

This delivers the username of the chosen user in my template. But i’d like to have his real Name (Name + Last Name) displayed…

How can i do that?

You can use

$user->lastName()
$user->firstName()

http://getkirby.com/docs/cheatsheet/user/lastname
e.g.

<?php
  $author = $page->autor();
   echo  $site->user($author)->firstname() . " " .  $site->user($author)->lastname();
?>

i edited the file /panel/app/fields/user/user.php and changed

$this->options[$user->username()] = $user->username();

to

$this->options[$user->firstName()] = $user->firstName();

That works fine…

But i cant get both working… firstName() AND firstName() :frowning:

Did you try the code I posted above in your template? It’s not a good idea to change the core …

i did…

your code displays always the firstname and lastname of the current logged in user

Edit: and it doesnt work if no one is logged in…

its working now after editing the core file user.php like this:

    <?php

class UserField extends SelectField {

  public function __construct() {
    $this->type    = 'text';
    $this->icon    = 'user';
    $this->label   = l::get('fields.user.label', 'User');
    $this->options = array();

    foreach(kirby()->site()->users() as $user) {
      $this->options[$user->firstName() . " " . $user->lastName()] = $user->firstName() . " " . $user->lastName();
    }

  }

  public function value() {
    $value = parent::value();
    return empty($value) ? site()->user()->firstName() : parent::value();
  }

}

Yes, i know… editing the core is quite bad… But it didn’t work any other way :confused:

I have no idea why it doesn’t work for you, because it has been working for me in the past and I just tested it again just to make sure. What version of Kirby are u using?

1 Like

I think @9zehn81 wants firstname and lastname to be displayed in the backend, too. But a better solution (because without hacking core) is the way @texnixe mentioned – and this worked for me. That means: username in the backend and then firstname and lastname in the frontend/templates.

i’m using the latest version: 2.1.0

@flokosiol: its not necessary to display firstname + lastname in the panel, the username would ne enough, if the full name would be displayed in the template. But even this didn’t work with @texnixe’s solution.

i’m using an “old” template from getkirby-themes.com… could this be the reason?

Aaaand: thanks for your help :slight_smile:

If you would post your code, it will be easier to check if there are any problems :smile: