Using conditional Statements in portal_welcome
#1
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
Not in this land alone,
But be God's mercies known,
From shore to shore!
Lord make the nations see,
That men should brothers be,
And form one family,
The wide world ov'er

Reply
#2
You can use this plugin to include conditionals in templates
http://mybbhacks.zingaburga.com/showthread.php?tid=464
Reply
#3
(07-23-2011, 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
Not in this land alone,
But be God's mercies known,
From shore to shore!
Lord make the nations see,
That men should brothers be,
And form one family,
The wide world ov'er

Reply
#4
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.
Reply
#5
(07-23-2011, 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>
Not in this land alone,
But be God's mercies known,
From shore to shore!
Lord make the nations see,
That men should brothers be,
And form one family,
The wide world ov'er

Reply
#6
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>
Reply
#7
(07-23-2011, 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
Not in this land alone,
But be God's mercies known,
From shore to shore!
Lord make the nations see,
That men should brothers be,
And form one family,
The wide world ov'er

Reply
#8
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.
Reply
#9
(07-23-2011, 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
Not in this land alone,
But be God's mercies known,
From shore to shore!
Lord make the nations see,
That men should brothers be,
And form one family,
The wide world ov'er

Reply
#10
(07-23-2011, 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
Not in this land alone,
But be God's mercies known,
From shore to shore!
Lord make the nations see,
That men should brothers be,
And form one family,
The wide world ov'er

Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)