MyBB Community Forums

Full Version: Template condition for group and forum
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is it possible to create one template condition that allow specific usergroup can see part of post in specific forum else all group can see all part of post in all forum?

e.g I want usergroup 8 and 9 to show some part of template in forum id 148,156 and 197. and in all other forums , all usergroup can see whole post.

<if !in_array($mybb->usergroup['gid'], array('8','9')) & !in array($foruminfo['fid'] == '148'  || $foruminfo['fid'] == '156' || $foruminfo['fid'] == '197'then>

<table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder1">
<tr>
<td class="thead1"><strong style="background-color: #C69A32;padding: 4px 11px 4px 14px;margin: -0.5%;color: #262626;"><i class="fa fa-user"></i> Welcome {$mybb->user['username']} </strong>
	</td>
</tr>
</table></br>

<else>


<table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder1">
<tr>
<td class="thead1"><strong style="background-color: #C69A32;padding: 4px 11px 4px 14px;margin: -0.5%;color: #262626;"><i class="fa fa-user"></i> Welcome {$mybb->user['username']} </strong>
	</td>
</tr>
<tr>
<td class="trow3">
<span><img class="avat" src="{$mybb->user['avatar']}" alt="My Avatar" title="My Avatar"/></span>
	<span style="float: right;padding: 12px 35px 0px 0px;">
	<div class="ublock"><a href="search.php?action=finduserthreads&uid={$mybb->user['uid']}"><i class="fa fa-th-large"></i> &nbsp;My threads</a></br>
	<a href="search.php?action=finduser&uid={$mybb->user['uid']}"><i class="fa fa-comments"></i> &nbsp;My posts </a></br>
	<a href="{$mybb->settings['bburl']}/private.php" title="Private Messages"><span><i class="menu-icon fa fa-envelope"></i>&nbsp; Messages&nbsp;<b class="pmboxcount" style="float: none;">{$mybb->user['pms_unread']}</b></a></br>
	<li style="display: block;"><a href="{$mybb->settings['bburl']}/search.php?action=getnew" > <i class="fa fa-tags"></i>&nbsp; New Posts</a></li>
			<li style="display: block;"><a href="{$mybb->settings['bburl']}/search.php?action=getdaily"> <i class="fa fa-star"></i>&nbsp; Today´s Posts</a></li></div>
		</span>
</td>
</tr>
</table>

</if>

Is above code is right?

Thank you.
On line 3, in PHP how you define "AND" inside an if statement is by two ampersand's (&&) not one.

Also you get the user(s) usergroup by $mybb->user['usergroup'] not by $mybb->usergroup

I'm guessing you've never done PHP before? Honestly pointing out the errors will take me way longer than just fixing it up, here I've fixed up your if statement:

<if in_array($mybb->user['usergroup'], array('8','9')) && in_array($foruminfo['fid'], array('148', '156', '197')) then>

Note that I've reversed it by removing the exclamation marks in front of !in_array too, I suggest you keep it simple stupid when no prior experience, no need to do a reverse logical statement when you can just do it like this and swap the content of the if content else content.

Some mistakes:
You were doing an in array without _ (functions in PHP cannot contain spaces so they are often linked by _ i.e. in_array() )

You had OR ( || < ) logical operator inside an in_array() function, for the forum ids, they should just be an array and be your second parameter.

I do not know if this will work, but give it a try.