Accessing User Groups in Template Code

Post By:user_67230 | Reply

We have recently upgraded our site to 3.3.3. In the template code we determine the user group of the logged in user and display content or not based on the user group.
The specific code is
<?php if($user->groups[8] || $user->groups[6]): ?>
<div id="boardmenu">
<jdoc:include type="modules" name="board" style="xhtml" />
</div>
<?php endif;?>

$user is defined earlier as $user =& JFactory::getUser();
I think it has something to do with the syntax of the "groups[8]" and "groups[6]" but I can't find the right syntax to use. Can you point me in the right direction?

Thanks
user_56604Sun, 24 Aug 2014

jackrabbit wrote:
User functions list at http://docs.joomla.org/Accessing_the_cu ... ser_object
If just to determine that the user has editing rights
Code:
if ($user->authorise('core.edit'))
Well, task permissions don't really fit in to the thing Karen is doing here...
example: For one component the group may has edit rights, for another one the group don't has the rights, but the div content should always be there for the group.

user_56121Sun, 24 Aug 2014

User functions list at http://docs.joomla.org/Accessing_the_cu ... ser_object
If just to determine that the user has editing rights

Code:
if ($user->authorise('core.edit'))

user_56604Sun, 24 Aug 2014

I don't know if something like this is in the documentation, I don't use that site much.

user_67230Sat, 23 Aug 2014

RedEye,

I did have error reporting on and it was an Offset error. The code you suggested worked. Thanks.

I tried to find the correct syntax from the Joomla documentation. But I never seem to look in the right place. Where should I look?
Karen

user_56604Sat, 23 Aug 2014

kkurtz wrote:
I think it has something to do with the syntax of the "groups[8]" and "groups[6]" but I can't find the right syntax to use. Can you point me in the right direction?
If you had error reporting enabled you would be able to see your problem (Undefined offset).
You could use the following for example.
Code:
<?php if(array_key_exists(6, $user->groups) || array_key_exists(8, $user->groups)): ?>
<div id="boardmenu">
   <jdoc:include type="modules" name="board" style="xhtml" />
</div>
<?php endif;?>

isset() would also be an option

user_56121Sat, 23 Aug 2014

Great method but what's the question? Are you getting an error message?

`Reply Or Comment!
Please LogIn to Reply!