Showing Content and Menus items to Mulit Groups

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
dmgd
Forum Members
Forum Members
Posts: 115
Joined: Tue Jun 06, 2006 1:10 pm
Location: TX

Showing Content and Menus items to Mulit Groups

Post by dmgd »

This has been done to death but here is my version.  Works for any number of groups and any number of pages.  No hard coding, just "set it and forget it"

Create your groups in FEU and on the pages that require user log in add the group name/s spelled exactly as it is in FEU groups separated by a comma "," in the extra1 field.  The menu template and page template use $ccuser->memberof() and extra1 information to display the menu item and content. The function memberof() accepts a comma separated list of group names so pages can be displayed to multiple groups.

Code: Select all

{* Template code for the content *}
          {page_attr key='extra1' assign='extra1'}
          {if ($ccuser->memberof($extra1) and $ccuser->loggedin()) or $extra1 == ''}
            {content}
          {else}
               <p>Please login first:</p>
               {cms_module module="FrontEndUsers"  nocaptcha="1"}
          {/if}

Code: Select all

{* ****************************
   MENU TEMPLATE
***************************** *}
{* CSS classes used in this template:
#menuwrapper - The id for the <div> that the menu is wrapped in. Sets the width, background etc. for the menu.
#primary-nav - The id for the <ul>
.menuparent - The class for each <li> that has children.
.menuactive - The class for each <li> that is active or is a parent (on any level) of a child that is active. *}
{if $count > 0}
<div id="menuwrapper">
<ul id="primary-nav">
{assign var="predepth" value=1}
{assign var="mminus" value=1}
{foreach from=$nodelist item=node}
{* Code added to allow multiple FEU Groups to view predetermined pages *}
{if (($ccuser->memberof($node->extra1) and $ccuser->loggedin()) or $node->extra1== '')}

{* end of new code *}
{if $node->depth > $predepth}
{repeat string='<ul class="unli">' times=$node->depth-$predepth}
{elseif $node->depth < $predepth}
{repeat string='</li><li class="separator once" style="list-style-type: none;"> </li></ul>' times=$predepth-$node->depth}
</li>
{elseif $node->index > 0}</li>
{/if}

{assign var="predepth" value=$node->depth}
{if $node->parent == true or ($node->current == true and $node->haschildren == true)}
<li class="menuactive menuparent">
<a class="menuactive menuparent" {elseif $node->current == true}
<li class="menuactive">
<a class="menuactive" {elseif $node->haschildren == true}
<li class="menuparent">
<a class="menuparent" {elseif $node->type == 'sectionheader' and $node->haschildren == true}
<li class="sectionheader"><span class="sectionheader">{$node->menutext}</span> {elseif $node->type == 'separator'}
<li style="list-style-type: none;"> <hr class="menu_separator" />{else}
<li>
<a {/if}
{if $node->type != 'sectionheader' and $node->type != 'separator'}
{if $node->target}target="{$node->target}" {/if}
href="{$node->url}"><span>{$node->menutext}</span></a>
{elseif $node->type == 'sectionheader'}
><span class="sectionheader">{$node->menutext}</span></a>
{/if}
{else}
{assign var="prevdepth" value=`$node->depth-$mminus`}
{/if} {* end if member or not *}
{/foreach}
{repeat string='</li><li class="separator once" style="list-style-type: none;"> </li></ul>' times=$node->depth-1}
</li>
</ul>
<div class="clearb"></div>
</div>
{/if}
Last edited by dmgd on Fri Aug 06, 2010 11:46 am, edited 1 time in total.
Mark
User avatar
manuel
Power Poster
Power Poster
Posts: 354
Joined: Fri Nov 30, 2007 9:15 am

Re: Showing Content and Menus items to Mulit Groups

Post by manuel »

Hi Dmgd,

Thanks for sharing this, it's working perfectly!

Greetings,
Manuel
Do you like your open source cms? Buy from the CMSMS partners || Donate
User avatar
manuel
Power Poster
Power Poster
Posts: 354
Joined: Fri Nov 30, 2007 9:15 am

Re: Showing Content and Menus items to Mulit Groups

Post by manuel »

Hi Dmgd,

In the code below, i show some small lock icon next to the members only pages in the menu. (and I removed the "separator once" items)

Code: Select all

{* ****************************
   MENU TEMPLATE
***************************** *}
{* CSS classes used in this template:
#menuwrapper - The id for the <div> that the menu is wrapped in. Sets the width, background etc. for the menu.
#primary-nav - The id for the <ul>
.menuparent - The class for each <li> that has children.
.menuactive - The class for each <li> that is active or is a parent (on any level) of a child that is active. *}
{if $count > 0}
<div id="menuwrapper">
<ul id="primary-nav">
{assign var="predepth" value=1}
{assign var="mminus" value=1}
{foreach from=$nodelist item=node}
{* Code added to allow multiple FEU Groups to view predetermined pages *}
{if (($ccuser->memberof($node->extra1) and $ccuser->loggedin()) or $node->extra1== '')}

{* end of new code *}
{if $node->depth > $predepth}
{repeat string='<ul class="unli">' times=$node->depth-$predepth}
{elseif $node->depth < $predepth}
{repeat string='</li></ul>' times=$predepth-$node->depth}
</li>
{elseif $node->index > 0}</li>
{/if}

{assign var="predepth" value=$node->depth}
{if $node->parent == true or ($node->current == true and $node->haschildren == true)}
<li class="menuactive menuparent">
<a class="menuactive menuparent" {elseif $node->current == true}
<li class="menuactive">
<a class="menuactive" {elseif $node->haschildren == true}
<li class="menuparent">
<a class="menuparent" {elseif $node->type == 'sectionheader' and $node->haschildren == true}
<li class="sectionheader"><span class="sectionheader">{$node->menutext}</span> {elseif $node->type == 'separator'}
<li style="list-style-type: none;"> <hr class="menu_separator" />{else}
<li>
<a {/if}
{if $node->type != 'sectionheader' and $node->type != 'separator'}
{if $node->target}target="{$node->target}" {/if}
href="{$node->url}">{if ($node->extra1!= '')}<div style="position:relative;"><img style="position:absolute;z-index:99;left:-14px;top:-2px;" src="custom/images/lock-icon.png"></div>{/if}<span>{$node->menutext}</span></a>
{elseif $node->type == 'sectionheader'}
>{if ($node->extra1!= '')}<div style="position:relative;"><img style="position:absolute;z-index:99;left:-14px;top:-2px;" src="custom/images/lock-icon.png"></div>{/if}<span class="sectionheader">{$node->menutext}</span></a>
{/if}
{else}
{assign var="prevdepth" value=`$node->depth-$mminus`}
{/if} {* end if member or not *}
{/foreach}
{repeat string='</li></ul>' times=$node->depth-1}
</li>
</ul>
<div class="clearb"></div>
</div>
{/if}
Greetings,
Manuel
Attachments
lock-icon.png
lock-icon.png (697 Bytes) Viewed 4259 times
Last edited by manuel on Wed Dec 29, 2010 5:50 pm, edited 1 time in total.
Do you like your open source cms? Buy from the CMSMS partners || Donate
User avatar
manuel
Power Poster
Power Poster
Posts: 354
Joined: Fri Nov 30, 2007 9:15 am

Re: Showing Content and Menus items to Mulit Groups

Post by manuel »

UPDATE: I was having some trouble with a multi language site showing a broken menu when the user wasn't logged in...

After looking in the code it appeared there where some tags missing from the menu.

I had to add {if $ccuser->loggedin()}{else}</li></ul>{/if} to the end of the template to fix it...

Code: Select all

{* ****************************
   MENU TEMPLATE
***************************** *}
{* CSS classes used in this template:
#menuwrapper - The id for the <div> that the menu is wrapped in. Sets the width, background etc. for the menu.
#primary-nav - The id for the <ul>
.menuparent - The class for each <li> that has children.
.menuactive - The class for each <li> that is active or is a parent (on any level) of a child that is active. *}
{if $count > 0}
<div id="menuwrapper">
<ul id="primary-nav">
{assign var="predepth" value=1}
{assign var="mminus" value=1}
{foreach from=$nodelist item=node}
{* Code added to allow multiple FEU Groups to view predetermined pages *}
{if (($ccuser->memberof($node->extra1) and $ccuser->loggedin()) or $node->extra1== '')}

{* end of new code *}
{if $node->depth > $predepth}
{repeat string='<ul class="unli">' times=$node->depth-$predepth}
{elseif $node->depth < $predepth}
{repeat string='</li></ul>' times=$predepth-$node->depth}
</li>
{elseif $node->index > 0}</li>
{/if}

{assign var="predepth" value=$node->depth}
{if $node->parent == true or ($node->current == true and $node->haschildren == true)}
<li class="menuactive menuparent">
<a class="menuactive menuparent" {elseif $node->current == true}
<li class="menuactive">
<a class="menuactive" {elseif $node->haschildren == true}
<li class="menuparent">
<a class="menuparent" {elseif $node->type == 'sectionheader' and $node->haschildren == true}
<li class="sectionheader"><span class="sectionheader">{$node->menutext}</span> {elseif $node->type == 'separator'}
<li style="list-style-type: none;"> <hr class="menu_separator" />{else}
<li>
<a {/if}
{if $node->type != 'sectionheader' and $node->type != 'separator'}
{if $node->target}target="{$node->target}" {/if}
href="{$node->url}">{if ($node->extra1!= '')}<div style="position:relative;"><img style="position:absolute;z-index:99;left:-14px;top:-2px;" src="custom/images/lock-icon.png"></div>{/if}<span>{$node->menutext}</span></a>
{elseif $node->type == 'sectionheader'}
>{if ($node->extra1!= '')}<div style="position:relative;"><img style="position:absolute;z-index:99;left:-14px;top:-2px;" src="custom/images/lock-icon.png"></div>{/if}<span class="sectionheader">{$node->menutext}</span></a>
{/if}
{else}
{assign var="prevdepth" value=`$node->depth-$mminus`}
{/if} {* end if member or not *}
{/foreach}
{repeat string='</li></ul>' times=$node->depth-1}
</li>
</ul>
{if $ccuser->loggedin()}{else}</li></ul>{/if}
<div class="clearb"></div>
</div>
{/if}
Greetings,
Manuel
Post Reply

Return to “Tips and Tricks”