| Re: Reading and computing group-ids with smarty |
| by frankblack on 2007/10/5 12:47:25 Or only smarty-based (found on myxoops.org): le="color: #000000"><?php <{php}> global $xoopsuser; if (in_array("1",($xoopsUser)?$xoopsUser->getGroups():array(XOOPS_GROUP_ANONYMOUS))) { <{/php]> .. if user is in the group <{php}> } else { <{/php}> .. for everybody else ... <{php}> } <{/php}>
|
| Re: Reading and computing group-ids with smarty |
| by iHackCode on 2007/10/5 12:22:14 another example. (its not using groupid though, but can be changed easily) https://xoops.org/modules/newbb/viewtopic.php?topic_id=32938&viewmode=flat&order=ASC&start=0#forumpost157003 using Dave's code, i use something like this in the templates and themes le="color: #000000"><?php <{if in_group('somegroupname')}> <b>html</b> <{/if}>
|
| Re: Reading and computing group-ids with smarty |
| by frankblack on 2007/10/5 11:15:12 I guess adding the snippet in theme.php or header.php makes no difference. I wanted to compute the array quite simple. And the simplest way from the viewpoint of a theme designer (without touching any php files) was to do this INSIDE the templates. So I came up with the added smarty-function for arrays. That's all. I know that there must be better solutions out there, but I did not find any.
|
| Re: Reading and computing group-ids with smarty |
| by nachenko on 2007/10/5 10:39:13 Hi, FrankBlack. I wrote a hack like this some time ago, don't know what's exactly your problem: I added this code in header.php about line 100: Quote: $xoopsTpl->assign( 'xoops_usergroups', $xoopsUser->getGroups() ); And this is the result in the Smarty console: Quote: {$xoops_usergroups} Array (4) See? It gives an array. What method did you use to attach it to the template? Did you use $xoopsTpl->assign() or did you use any other method? |
| Reading and computing group-ids with smarty |
| by frankblack on 2007/10/5 9:50:38 Perhaps there is a much more elegant way? I needed this for myself and did not found a better solution. The following code is for XOOPS 2.0.17 1. edit class/theme.php and add after line 199 the following code: le="color: #000000"><?php 'xoops_getgroups' => $xoopsUser->getGroups(), 2. in the template it looks like this: le="color: #000000"><?php <{if array_intersect('1', $xoops_getgroups)}>if user is in group 1, do anything<{/if}> Addendum: Of course it is bad if you need an array and AFAIK there is no way to make an array INSIDE a template. You have to assign the array in the PHP-file to the template. Thanks to google I have found a function where you can build arrays inside a template. 1. save the following code as file function.assign_array.php in class/smarty: 2. the template looks now like this: le="color: #000000"><?php <{assign_array var="gruppen" values="1,2"}><{if array_intersect($gruppen, $xoops_getgroups)}>if there is an intersection, do anything<{/if}> It seems to be that other array-functions like in_array etc.pp. are working also with this code. Enjoy trying.
|