TYPO3 - 将已登录用户的用户组渲染为流体中的逗号分隔字符串

时间:2018-02-12 21:21:13

标签: typo3 extbase typo3-8.x typo3-extensions

如何将已登录用户的用户组渲染为流畅的逗号分隔字符串?所以我想这样:

3,9

控制器:

$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)
   ...

2 个答案:

答案 0 :(得分:1)

您可以使用while ($stmt->fetch()) { if( !isset($json[$masterid]) ) $json[$masterid] = array(); $json[$masterid][] = array( 'date' => $temperaturetime, 'volume' => $beerline, 'value' => $temperature ); } viewhelper执行此操作,如下所示。

f:for

答案 1 :(得分:0)

<f:for each="{user.usergroup}" as="usergroupItem" iteration="iterator">
    {usergroupItem.uid}
    <f:if condition="{iterator.isLast}">
        <f:else>, </f:else>
    </f:if>
</f:for>