MyBB Community Forums

Full Version: Using conditional Statements in portal_welcome
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi
I have nearly got the result I want, that is to replace the panel with all the links in a box ... leaving the panel just to display the user name & current time .. I thought I could use an if statement to turn off the display of certain things in portal_welcome like :-
<if $mybb->user['uid'] then>
<span class="smalltext">
<a href="#" onclick="MyBB.popupWindow('{$mybb->settings['bburl']}/misc.php?action=buddypopup', 'buddyList', 350, 350);">{$lang->welcome_open_buddy_list}</a><br>
<a href="{$mybb->settings['bburl']}/private.php"><span class="smalltext">{$lang->welcome_pms}</a><br> <span class="smalltext">{$lang->welcome_pms_usage}<br>
</if>
so as you can see I have checked for a user id and I guessed the other lines should be executed if the condition was true but mybb seems to ignore the if statement .. unless my poor knowledge of programing has made a mistake
You can use this plugin to include conditionals in templates
http://mybbhacks.zingaburga.com/showthread.php?tid=464
(2011-07-23, 06:00 PM)x-Treme Wrote: [ -> ]You can use this plugin to include conditionals in templates
http://mybbhacks.zingaburga.com/showthread.php?tid=464

That worked ... thanks so the next step is to add some if statements to cover user groups rather than just logged in or not any idea on which variable I need to test to find the user group ?

Regards Jim
You can use this:

<if in_array($GLOBALS['mybb']->user['usergroup'], array(4,5,6)) then>
//Example
</if>

Replace 4,5,6 with the GIDs of the groups you want to display the content to.
(2011-07-23, 06:31 PM)faviouz Wrote: [ -> ]You can use this:

<if in_array($GLOBALS['mybb']->user['usergroup'], array(4,5,6)) then>
//Example
</if>

Replace 4,5,6 with the GIDs of the groups you want to display the content to.

ok that sounds good so by the same token will the following work :-
<if in_array($GLOBALS['mybb']->user['usergroup'], array(4)) then>
//Example
<elseif in_array($GLOBALS['mybb']->user['usergroup'], array(5)) then>
//do something else
</if>
Yes, but if you only want to work with one GID then you don't need to use an array. Do this instead:

<if $GLOBALS['mybb']->user['usergroup'] == 4 then>
//Example
<elseif $GLOBALS['mybb']->user['usergroup'] == 5 then>
//do something else
</if>
(2011-07-23, 07:29 PM)faviouz Wrote: [ -> ]Yes, but if you only want to work with one GID then you don't need to use an array. Do this instead:

<if $GLOBALS['mybb']->user['usergroup'] == 4 then>
//Example
<elseif $GLOBALS['mybb']->user['usergroup'] == 5 then>
//do something else
</if>

thanks for that .... just a thought would
<if $GLOBALS['mybb']->user['usergroup'] => 3 then>
//Example say mod or greater
<elseif $GLOBALS['mybb']->user['usergroup'] == 5 then>
//do something else say admin
</if>
if the above works that would give me the replacement for the panel links ... which I hope to move to the toplinks menu area, so the result in toplinks would be "User CP Mod CP Admin CP Log Out" and the post/pm information moved to portal_welcome. just leaving current time & user welcome in the panel. have a look at what I have done so far
I don't think so. But what you're trying to achieve is perfectly possible. Try this:

<if in_array($GLOBALS['mybb']->user['usergroup'], array(1,2,3)) then>
//Example say mod or greater
<elseif $GLOBALS['mybb']->user['usergroup'] == 5 then>
//do something else say admin
</if>

Replace 1,2,3 with the GIDs of the usergroups you want.
(2011-07-23, 07:54 PM)faviouz Wrote: [ -> ]I don't think so. But what you're trying to achieve is perfectly possible. Try this:

<if in_array($GLOBALS['mybb']->user['usergroup'], array(1,2,3)) then>
//Example say mod or greater
<elseif $GLOBALS['mybb']->user['usergroup'] == 5 then>
//do something else say admin
</if>

Replace 1,2,3 with the GIDs of the usergroups you want.

The array did not seem to work so I did a conditional on each group worked fine ,,,, could have done with a for next loop
(2011-07-23, 07:54 PM)faviouz Wrote: [ -> ]I don't think so. But what you're trying to achieve is perfectly possible. Try this:

<if in_array($GLOBALS['mybb']->user['usergroup'], array(1,2,3)) then>
//Example say mod or greater
<elseif $GLOBALS['mybb']->user['usergroup'] == 5 then>
//do something else say admin
</if>

Replace 1,2,3 with the GIDs of the usergroups you want.

ok I have got that code sorted but how do I handle this type of code ?
<if $mybb->user['uid'] then>
<td class="thead"><strong>At a Glance</strong></td>
<elseif $mybb->user['uid']==0 then>
<td class="thead"><strong>Log in or register</strong></td>
</if>
This does not work for some reason or should I be using =="" or ==''

Regards Jim
got it to work my typo Smile