Templating condition. If in group

All style (template, theme and imageset) related questions for the new release; advice, feedback here please.
Post Reply
Bbbbrent
Registered User
Posts: 3
Joined: Thu Dec 07, 2006 10:09 am

Templating condition. If in group

Post by Bbbbrent »

I'm working on a site integration with phpbb3. Going well, except this.
My navigational bar displays some tabs based on whether or not a user is in a group.
For outside the forum i've just been including the necessary files and calling

Code: Select all

if( group_memberships( 12, $user->data['user_id'] ) != false ) )
{
   // show
}
 
I need a solution but in the template mark up. I've searched but I could not find a way. Does a way exist?
If not, i could also allow php in my template files, but that would be my last solution.

Thanks,
Brent.

User avatar
stickerboy
Registered User
Posts: 94
Joined: Fri Jun 04, 2004 3:05 pm
Location: Scotland
Contact:

Re: Templating condition. If in group

Post by stickerboy »

I can't seem to find the original post with the details in it, but there's the code (I did not write this code):

*Code has been updated* - 10:09 28/02/2009

OPEN: includes/functions.php
FIND:

Code: Select all

	// application/xhtml+xml not used because of IE
BEFORE ADD:

Code: Select all

	// Check what group a user is in
	if ( !function_exists('group_memberships') )
	{
		include_once($phpbb_root_path . 'includes/functions_user.'.$phpEx);
	}

	$groups = group_memberships(false,$user->data['user_id']);
	foreach ($groups as $grouprec)
	{
		$template->assign_vars(array(
			'S_IN_GROUP_' . $grouprec['group_id'] => true
		));
	}
Now in any template file you can use

Code: Select all

<!-- IF S_IN_GROUP_X -->
. . . foo . . .
<!-- ELSE -->
. . . bar . . .
<!-- ENDIF -->  
Repalce X with the id of the group you wish to utilise :)
Last edited by stickerboy on Sat Feb 28, 2009 10:10 am, edited 1 time in total.
Reason: Code fixed as per post below
I'm a web-designing code-decrypting tech-support musician
|| Twitter || Flickr || phpBB Snippets ||
Formerly known as cherokee red

Bbbbrent
Registered User
Posts: 3
Joined: Thu Dec 07, 2006 10:09 am

Re: Templating condition. If in group

Post by Bbbbrent »

Thanks heaps!
Seems odd that such a thing isn't already built in. Oh well, future release maybe.

User avatar
Acyd Burn
Posts: 1838
Joined: Tue Oct 08, 2002 5:18 pm
Location: Behind You
Contact:

Re: Templating condition. If in group

Post by Acyd Burn »

Because a call to group_memberships() is time consuming and therefore we do not want to call it on every page view.

Image

Bbbbrent
Registered User
Posts: 3
Joined: Thu Dec 07, 2006 10:09 am

Re: Templating condition. If in group

Post by Bbbbrent »

[fixed] This post is now irrelevant
For future reference there is a typo in the code. Either change

Code: Select all

'S_GROUP_' . $grouprec['group_id'] => true
to

Code: Select all

'S_IN_GROUP_' . $grouprec['group_id'] => true
or use

Code: Select all

<!-- IF S_GROUP_X -->
. . . foo . . .
<!-- ELSE -->
. . . bar . . .
<!-- ENDIF --> 
Last edited by Bbbbrent on Sat Feb 28, 2009 10:27 am, edited 1 time in total.

User avatar
stickerboy
Registered User
Posts: 94
Joined: Fri Jun 04, 2004 3:05 pm
Location: Scotland
Contact:

Re: Templating condition. If in group

Post by stickerboy »

Updated my post, thanks for spotting that ;)
I'm a web-designing code-decrypting tech-support musician
|| Twitter || Flickr || phpBB Snippets ||
Formerly known as cherokee red

Post Reply