How to show username in frontend in TYPO3 10?

2.1k views Asked by At

In TYPO3 9 I managed to display the current username in a FLUID-template with the following Typoscript:

[loginUser=*]
    temp.username = TEXT
    temp.username {
        insertData = 1
        value = {TSFE:fe_user|user|username}
        noTrimWrap = | ||
    }
[global]

In TYPO3 10.4 this is not working anymore. Any idea how to display the current user? Many thanks! Urs

3

There are 3 answers

3
Florian Rival On BEST ANSWER

In Typo3 V10, you have to use the Context API to retrieve data from global objects, try this :

[frontend.user.isLoggedIn]
temp.username = TEXT
temp.username.data = TSFE:fe_user|user|name
temp.username.wrap = |
[global]

Have a look at those links :

https://docs.typo3.org/m/typo3/reference-typoscript/master/en-us/DataTypes/Index.html https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Context/Index.html#context-api

Florian

1
Rudy Gnodde On

It's probably not working because you're using the old TypoScript conditions. Since TYPO3 9 the conditions work with Symfony expressions. The old conditions were deprecated in TYPO3 9 (but still worked) and removed in TYPO3 10. So [loginUser=*] will never be true in TYPO3 10. You should use [frontend.user.isLoggedIn] instead.

See https://docs.typo3.org/m/typo3/reference-typoscript/master/en-us/Conditions/Index.html for more about the new TypoScript conditions.

2
Aristeidis Karavas On

Why use TypoScript? It is very limited on what it can bring back. I just finished a tutorial where you can use a ViewHelper to add an ExtBase variable which assigns the whole user object in the FrontEnd and you can use it wherever you want with all it's relations, even the image, which is difficult to get via TypoScript.

TYPO3 tutorial

Best regards