Ibexa DXP Discussions

Community discussion forum for developers working with Ibexa DXP

Displaying user's first name? (Accessing logged-in user data in a template)

I want to display the user’s first name in the header, after logging into my site.

I assume since the user status is required for every page load that there would be some data accessible via the template. I found that app.user is accessible, but I can find no ez documentation, nor any symfony documentation, that leads me in the right direction of accessing the name fields in the template.

Solutions I’ve found in forums regarding Symfony (non-ezplatform) do not work {{app.user.first_name}}, for example.

I thought this would be straightforward, but I’ve spent all day combing docs trying to find a solution, and could find none. Any help would be appreciated.

app.user from Symfony has an additional property, app.user.APIUser, which returns the currently logged in eZ user.

You can use {{ ez_render_field(app.user.APIUser.content, 'first_name') }} to display the first name of the user, provided you didn’t change your user content type and it still has the first_name field.


Thanks for your help! That worked.

If possible, could you point me to where you found this info? Because even after reading and implementing your solution, I was unable to find any reference to it online. So I’m not sure what other functionality of the user class is available to me that I’m currently unaware of.

Thanks again for the help! It’s greatly appreciated.

I honestly don’t know. It probably comes from reading the kernel code sometime in the past :slight_smile:

You can just dump the app and ezpublish variables in your twig templates to see what they have.

1 Like

I had dumped the variable, but the fields I needed were protected, and I couldn’t find the get functions to handle their retrieval. In any case, I have this now as a reference!

Thanks for your help!

You can always open the classes in question (Symfony\Bridge\Twig\AppVariable and eZ\Publish\Core\MVC\Symfony\Templating\GlobalHelper) and check out the methods they have.

1 Like