I'am using femanager to manage user registration, login and logout.
Like many other websites, I'd like to show some user information on the top of the page (using Boostraps mini-navbar).
- If the user is logged out, this should look like:
- If the user is logged in, this information should displayed:
As a Typo3 beginner, I implement this with Typo Script and a partial in Fluid Template. The Typo Script reads the current user (user id and e-mail address).
userdata = COA_INT
userdata {
10 = TEXT
10.data = TSFE:fe_user|user|uid
20 = TEXT
20.data = TSFE:fe_user|user|username
}
The partial uses the user id to check if the user is logged in or logged out.
<f:if condition="{f:cObject(typoscriptObjectPath: 'userdata.10')} > 0">
<f:then>
<!-- user is logged in -->
<span class="greeting">
<i class="fa fa-user"></i> <f:cObject typoscriptObjectPath="userdata.20" />
</span>
<f:link.page pageUid="319" additionalParams="{logintype: 'logout'}" class="pull-right"><i class="fa fa-power-off"></i> Logout</f:link.page>
</f:then>
<f:else>
<!-- user is logged out -->
<span class="greeting">
Test it for free
</span>
<f:link.page pageUid="317" class="pull-right"><i class="fa fa-arrow-circle-down"></i> Register</f:link.page>
<f:link.page pageUid="319" class="pull-right"><i class="fa fa fa-sign-in"></i> Log in</f:link.page>
</f:else>
</f:if>
This works OK but I have problems with caching. Sometimes the mini-navbar is shown for an other user.
My question is: How can I prevent the partial from caching?
Caching in Partials can be tricky sometimes..
Take a look at the security viewhelper within the VHS viewhelper collection. It has some nice functionality which covers your case:
See the documenation for more information.