This section contains detailed articles elaborating on some of the common issues phpBB users encounter while using the product. Articles submitted by members of the community are checked for accuracy by the relevant phpBB Team. If you do not find the answer to your question here, we recommend looking through the Support Section as well as using the Site Wide Search.

Creating group template switches [NOTE-obsolete] An extension is available.

Description: This article explains how to create a template switch to control the display of elements to a certain group or groups.

In Categories:

Link to this article: Select All
[url=]Knowledge Base - Creating group template switches [NOTE-obsolete] An extension is available.[/url]

It is often desirable to display certain elements, such as links or images, only to the members of certain groups. As the revised title says, there is now an extension for this - viewtopic.php?f=456&t=2325391

To do this, OPEN includes/functions.php


CODE: Select all

  // The following assigns all _common_ variables that may be used at any point in a template.
BEFORE, on a separate line, ADD:

CODE: Select all

        if ( !function_exists('group_memberships') )
            include($phpbb_root_path . 'includes/functions_user.'.$phpEx);
        $groups = group_memberships(false,$user->data['user_id']);
        foreach ($groups as $grouprec)
            'S_GROUP_' . $grouprec['group_id'] => true
Then, you can use a switch in a template like this:

CODE: Select all

<!-- IF S_GROUP_N -->some stuff here<!-- ENDIF -->

CODE: Select all

<!-- IF S_GROUP_N or S_GROUP_X -->some stuff here<!-- ENDIF -->

CODE: Select all

<!-- IF not S_GROUP_N -->some stuff here<!-- ENDIF -->
Replace the "N" or "X" in the above code with the actual group_id of the group in question.

One easy way to determine the group_id is to go to the ACP, Manage groups, and hover your cursor over the Settings option for that group. At the bottom of the browser, the last part of the link will say "g=N", where N is the group_id.


Remember to refresh your style's templates in the ACP, Styles tab after inserting the switched element.

Credit for this code goes to RMcGirr83