Documentation · ViewHelper reference

Be / Security / IfHasRoleViewHelper


This view helper implements an ifHasRole/else condition for BE users/groups.

Examples

Basic usage

<f:be.security.ifHasRole role="Administrator">
This is being shown in case the current BE user belongs to a BE usergroup (aka role) titled "Administrator" (case sensitive) </f:be.security.ifHasRole>

Output

Everything inside the <f:ifHasRole> tag is being displayed if the logged in BE user belongs to the specified role.

Using the usergroup uid as role identifier

<f:be.security.ifHasRole role="1">
This is being shown in case the current BE user belongs to a BE usergroup (aka role) with the uid "1" </f:be.security.ifHasRole>

Output

Everything inside the <f:ifHasRole> tag is being displayed if the logged in BE user belongs to the specified role.

IfRole / then / else

<f:be.security.ifHasRole role="Administrator">
<f:then>
This is being shown in case you have the role. </f:then> <f:else>
This is being displayed in case you do not have the role. </f:else> </f:be.security.ifHasRole>

Output

Everything inside the "then" tag is displayed if the logged in BE user belongs to the specified role.
Otherwise, everything inside the "else"-tag is displayed.

  • Tag usage example

    <f:be.security.ifHasRole then="[mixed]" else="[mixed]" role="NULL">
    	<!-- tag content - may be ignored! -->
    </f:be.security.ifHasRole>
  • Inline usage example

    {f:be.security.ifHasRole(then: [mixed], else: [mixed], role: 'NULL')}

Arguments

Argument Description Type
else

Value to be returned if the condition if not met.

mixed
role

The usergroup (either the usergroup uid or its title).

string
then

Value to be returned if the condition if met.

mixed
Required attribute

Revision history

commit f9a55bd12cea48994973fc0a3f21011f499cc4ae
Author: Bastian Waidelich <*****@typo3.org>
Date:   Mon Sep 20 16:38:36 2010 +0000

    [+FEATURE] Fluid (ViewHelpers): Backported ifAuthenticated & ifHasRole security ViewHelpers
    
    you can now use <f:security.ifAuthenticated> and <f:security.ifHasRole role="foo">
    in your Fluid templates to check whether an FE user is currently logged in / belongs to the
    specified usergroup.
    Note: if role is a numeric value the uid of the usergroup is compared, otherwise the title
    of the usergroup.
    
    to deal with BE users you can use the respective be.security.* view helpers
    
    Resolves #9143

commit fd09d197fa8886b97cb20aa9573f39cd08ce989e
Author: Bastian Waidelich <*****@typo3.org>
Date:   Thu Nov 10 18:27:58 2011 +0100

    [TASK] S*****@author annotations
    
    This backports three recent changes of the TYPO3.Fluid package:
    - R*****@license annotation from files (290f4f5)
    - Simplify license header in PHP files (14bacba)
    - D*****@author tags from source code (9c2e837)
    
    This should not contain any functional change!
    
    Change-Id: I9376dca4af78c4f0f82413011d115b8ad04634dd

commit ca40f8a066da4ea3c849d74f68a9bc73758976c5
Author: dkd-egerer Sascha Egerer <*****@dkd.de>
Date:   Sat Apr 14 21:43:10 2012 +0200

    [TASK] Remove trailing whitespace
    
    There must be no empty lines after the closing
    PHP tag. Empty lines after closing tags break
    output compression in PHP and/or result in AJAX
    errors.
    
    Change-Id: I0484ca29d8134d0828cf30880d5aafd43ed9d78e
    Resolves: #36076
    Releases: 6.0
    Reviewed-on: http://review.typo3.org/10499
    Reviewed-by: Ingo Pfennigstorf
    Tested-by: Ingo Pfennigstorf
    Reviewed-by: Daniel Lorenz
    Tested-by: Daniel Lorenz
    Reviewed-by: Christian Kuhn
    Tested-by: Christian Kuhn

commit ec3891d8d4e339d8319428211207e6201be9fd73
Author: Thomas Maroschik <*****@dfau.de>
Date:   Wed Oct 17 21:18:26 2012 +0200

    [TASK][WIP] Move non class code back to source files
    
    Change-Id: I620d2e61860142cdc89cc83474c95542799961c0

commit 554e8f890dcc0dd86a27518b58e2b54be26fd37e
Author: Thomas Maroschik <*****@dfau.de>
Date:   Wed Oct 17 22:20:17 2012 +0200

    [TASK] Namespace classes
    
    Change-Id: Ia7432e1c923826ed58206bca15fb94509adbd508

commit 9d13dedf017b614b834261b1bf5d4acb2201f1d4
Author: Alexander Schnitzler <*****@typovision.de>
Date:   Fri Nov 16 19:49:02 2012 +0100

    [CLEANUP] Replace FLOW3 with TYPO3 Flow
    
    Releases: 6.0
    Fixes: #43036
    Change-Id: I62df23587301b4cde3ddeae3686b34f54fe1182e
    Reviewed-on: http://review.typo3.org/16498
    Reviewed-by: Alexander Schnitzler
    Tested-by: Alexander Schnitzler

commit 9d46e6932d35c79bf87c96fa38b8e537c4192f23
Author: Alexander Schnitzler <*****@typovision.de>
Date:   Tue Nov 20 16:27:02 2012 +0100

    [CLEANUP] Adjust code to CGL and fix small namespace bugs
    
    * whitespaces, tabs and blank line issues
    * bool -> boolean
    * int -> integer
    * fix wrong namespace annotations
    
    Fixes: #43157
    Releases: 6.0
    Change-Id: I8397948e19248db029d8efd1555ee56e4982742d
    Reviewed-on: http://review.typo3.org/16619
    Reviewed-by: Helmut Hummel
    Tested-by: Helmut Hummel

commit 77f29a3c69a7cbb27b34072754aa503bace6c9f1
Author: Christian Kuhn <*****@schwarzbu.ch>
Date:   Tue Oct 1 14:40:56 2013 +0200

    [TASK] Remove closing PHP tags
    
    Change-Id: Iaa92566c53301e49396fc9fb26b0b339c48d567b
    Resolves: #52360
    Releases: 6.2
    Reviewed-on: https://review.typo3.org/24212
    Reviewed-by: Christian Kuhn
    Tested-by: Christian Kuhn
    Reviewed-by: Ernesto Baschny
    Tested-by: Ernesto Baschny
    Reviewed-by: Anja Leichsenring
    Tested-by: Anja Leichsenring

commit 9646d26bac991dd23b5d58e7b85ab72d7a4af870
Author: Jo Hasenau <*****@cybercraft.de>
Date:   Sat Feb 1 21:49:09 2014 +0100

    [TASK] Use (int) instead of intval() or (integer)
    
    This patch replaces most of around 1600 occurrences of
    intval() and every (integer) in the whole core.
    Additionally it changes GeneralUtility::intExplode to use references
    and typecasting as well.
    Some occurrences of strstr() together with intval() have been replaced
    with strpos() as well.
    And some superfluous intval calls have been removed or reduced
    to a single one i.e. for protected variables or before loops.
    Patch updated after Core CGL decision from 30.01.2014
    
    Resolves: #54265
    Releases: 6.2
    Change-Id: Iba57ffad1f4233ffa1a9f7d3ca5bfe9d2b53f1e8
    Reviewed-on: https://review.typo3.org/26740
    Reviewed-by: Stefan Neufeind
    Tested-by: Stefan Neufeind