Subject:*
<
Name/Email:*
<
Message Icon:*
<
Select*
<
Message:*
<



Click the Preview to see the content in action.
Options:*
<
Confirmation Code*
<
2 + 9 = ?  
Input the result from the expression
Maximum attempts you can try: 10
*
<
     

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)
0 => 1
1 => 2
2 => 15
3 => 16


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:
<?php /* * Smarty plugin * ------------------------------------------------------------- * Type: function * Name: assign_array * Version: 1.0 * Author: Jens Lehmann <jenslehmann@goldmail.de> * Credits: Monte Ohrt <monte@ohrt.com> * Purpose: assign an array to a template variable * Input: var = name of the array * values = list of values (seperated by delimiter) * delimiter = value delimiter, default is "," * * Examples: {assign_array var="foo" values="bar1,bar2"} * {assign_array var="foo" values="bar1;bar2;bar3" delimiter=";"} * ------------------------------------------------------------- */ function smarty_function_assign_array($params, &$smarty) { extract($params); if(empty($delimiter)) { $delimiter = ','; } if (empty($var)) { $smarty->trigger_error("assign_array: missing 'var' parameter"); return; } if (!in_array('values', array_keys($params))) { $smarty->trigger_error("assign_array: missing 'values' parameter"); return; } $smarty->assign($var, explode($delimiter,$values) ); } /* vim: set expandtab: */ ?>


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.

Who's Online

196 user(s) are online (151 user(s) are browsing Support Forums)


Members: 0


Guests: 196


more...

Donat-O-Meter

Stats
Goal: $15.00
Due Date: Jul 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $15.00
Make donations with PayPal!

Latest GitHub Commits