Page 1 of 1

Showing Content and Menus items to Mulit Groups

Posted: Thu Aug 05, 2010 10:09 pm
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}

Re: Showing Content and Menus items to Mulit Groups

Posted: Wed Dec 29, 2010 4:29 pm
by manuel
Hi Dmgd,

Thanks for sharing this, it's working perfectly!

Greetings,
Manuel

Re: Showing Content and Menus items to Mulit Groups

Posted: Wed Dec 29, 2010 5:47 pm
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

Re: Showing Content and Menus items to Mulit Groups

Posted: Thu Mar 24, 2011 3:09 pm
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