1
dreamgear
accessing group membership info from Smarty
  • 2004/3/15 1:12

  • dreamgear

  • Friend of XOOPS

  • Posts: 78

  • Since: 2002/7/18


What would be the easiest way to push the list of groups a user is a member of into a Smarty variable ? Can anyone give a few pointers ?

A site I'm working on will have three levels of access: Anonymous, Logged in members, and a special class of members who are actually part of this organization.

I'm already conditionally (with Smarty) writing my javascript menus based on whether the user is logged in or not. I'd like to also do this based on group membership, but the info just doesn't seem to be there in the Smarty variables assigned now.

2
dreamgear
Re: accessing group membership info from Smarty
  • 2004/3/15 3:08

  • dreamgear

  • Friend of XOOPS

  • Posts: 78

  • Since: 2002/7/18


diff header.php.original header.php
91c91
< $xoopsTpl->assign(array('xoops_isuser' => true, 'xoops_userid' => $xoopsUser->getVar('uid'), 'xoops_uname' => $xoopsUser->getVar('uname'), 'xoops_isadmin' => $xoopsUserIsAdmin));
---
> $xoopsTpl->assign(array('xoops_isuser' => true, 'xoops_userid' => $xoopsUser->getVar('uid'), 'xoops_uname' => $xoopsUser->getVar('uname'), 'xoops_isadmin' => $xoopsUserIsAdmin, 'xoops_ugroups' => $xoopsUser->getGroups()));



3
dreamgear
Re: accessing group membership info from Smarty
  • 2004/3/15 5:00

  • dreamgear

  • Friend of XOOPS

  • Posts: 78

  • Since: 2002/7/18


And, for completeness, some smarty code to use this new information. This will print "IS_MOS" if the user is in the group with group id "4":

<{foreach from=$xoops_ugroups item=curr_gid}>
<{if $curr_gid eq "4"}>
<{assign var="is_mos" value="true"}>
<{/if}>
<{/foreach}>
<{if $is_mos}>

IS_MOS

<{/if}>


4
simonvl
Re: accessing group membership info from Smarty
  • 2004/4/4 8:02

  • simonvl

  • Just popping in

  • Posts: 44

  • Since: 2004/1/28


Brilliant Dreamgear. Thanks a lot! Just what I was looking for.
Simon

5
Mithrandir
Re: accessing group membership info from Smarty

Good job

I would recommend that you make changes to header.php and similar core files in separate files, so you only have to add one line (include [filename]) in future upgraded core files.

Easier than remembering all the changes, if there are many.

6
dreamgear
Re: accessing group membership info from Smarty
  • 2004/4/4 17:23

  • dreamgear

  • Friend of XOOPS

  • Posts: 78

  • Since: 2002/7/18


Thanks, and thanks for the tip wrt the changes to core files. I've mostly resisted making this kind of change because I don't want to have things break on updates.

Also, if someone was actually contemplating putting this change into the next core (hint, hint ) , I would like to have the groups represented by name instead of by group id.

Login

Who's Online

384 user(s) are online (280 user(s) are browsing Support Forums)


Members: 0


Guests: 384


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits