Reputation: 3488
How can I render the usergroups of a logged in user as a comma separated string in fluid? So I would like to the this:
3,9
Controller:
$user = $this->userRepository->findByUid($GLOBALS['TSFE']->fe_user->user['uid']);
$this->view->assign('user', $user);
List.html
<f:layout name="Default" />
<f:section name="main">
<f:debug>{user}</f:debug>
</f:section>
Extbase Variable Dump
TYPO3\CMS\Extbase\Domain\Model\FrontendUser prototype persistent entity (uid=4, pid=25)
username => protected 'testuser01' (10 chars)
password => protected 'sdfgsdxxcxsdf' (34 chars)
usergroup => protectedTYPO3\CMS\Extbase\Persistence\ObjectStorage prototype object (2 items)
00000000sdffsa => TYPO3\CMS\Extbase\Domain\Model\FrontendUserGroup prototype persistent entity (uid=3, pid=25)
title => protected 'Group 1' (7 chars)
uid => protected 3 (integer)
...
0000000werwerw => TYPO3\CMS\Extbase\Domain\Model\FrontendUserGroup prototype persistent entity (uid=9, pid=25)
title => protected 'Group 2' (7 chars)
...
uid => protected 9 (integer)
...
name => protected 'Test User 01' (12 chars)
firstName => protected 'Test' (4 chars)
...
Upvotes: 0
Views: 638
Reputation: 3207
You can do this using f:for
viewhelper like below.
<f:for each="{user.usergroup}" as="group" iteration="iterator">
{group.uid}
<f:if condition="{iterator.isLast}">
<f:then> </f:then>
<f:else>,</f:else>
</f:if>
</f:for>
Upvotes: 1
Reputation: 10791
<f:for each="{user.usergroup}" as="usergroupItem" iteration="iterator">
{usergroupItem.uid}
<f:if condition="{iterator.isLast}">
<f:else>, </f:else>
</f:if>
</f:for>
Upvotes: 0