TYPO3 10.3: Username in frontend

喜夏-厌秋 提交于 2021-01-24 22:06:55

问题


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


回答1:


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:


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




回答3:


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



来源:https://stackoverflow.com/questions/61746400/typo3-10-3-username-in-frontend

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!