I am trying to create a members area on a website. I want the private page to show up on the menu when the user correctly logs in.
I meet all of these requirements below:
calguy1000 wrote:
Requirements:
CMS Made Simple 1.0.5 or greater
CustomContent 1.4.4 or Greater
MenuManager 1.4 or Greater
FrontEndUsers (version shouldn't matter much)
In this step I pasted this information into my private page's metadata field and changed this: {if isset($customcontent_memberof_group1)} to this: {if isset($customcontent_memberof_ambassadors}. Which is a group that I had already created and assigned a test user to.
Steps:
1. In the metadata field of each of your private pages, add code similar to this: (change your group names as required)
Code: Select all
{assign var='content_is_visible' value='0'}
{if $customcontent_loggedin > 0}
{if isset($customcontent_memberof_group1)}
{assign var='content_is_visible' value='1'}
{/if}
{/if}
I created a user defined tag with the code below and named it groups_to_prefixes
2. Add this user defined tag, named: groups_to_prefixes
Code: Select all
$postfix = '_';
if( isset($params['postfix']) )
{
$postfix = trim($params['postfix']);
}
$adjustcase =1;
if( isset($params['noadjustcase']) )
{
$adjustcase = 0;
}
if( isset($params['groups']) )
{
$groups = explode(',',$params['groups']);
for( $i = 0; $i < count($groups); $i++ )
{
if( $groups[$i] != '' )
{
if( $adjustcase == 1 )
{
$groups[$i] = strtolower($groups[$i].$postfix);
}
else
{
$groups[$i] = $groups[$i].$postfix;
}
}
}
return implode(',',$groups);
}
return '';
I placed the code below within my template where I want the menu to be. And I changed this: {cms_module module='menumanager' template='andreas01 : andreasmenu' collapse='1' number_of_levels='2' includeprefix=$includeprefix} to this: {cms_module module='menumanager' template='header_menu' collapse='1' number_of_levels='2' includeprefix=$includeprefix} where header_menu is the name of my menu template.
3. Adjust your menu call in your template like this:
Code: Select all
{assign var='includeprefix' value='public_'}
{if $customcontent_loggedin > 0}
{capture assign='includeprefix'}{$includeprefix},{groups_to_prefixes groups=$customcontent_groups}{/capture}
{/if}
{cms_module module='menumanager' template='andreas01 : andreasmenu' collapse='1' number_of_levels='2' includeprefix=$includeprefix}
I pasted the code blow into the content area of my templates and did not change anything.
4. Adjust your content area in your template like this:
Code: Select all
{if !isset($content_is_visible)}
{* assume public content, unless the variable is already set *}
{assign var='content_is_visible' value='1'}
{/if}
{if $content_is_visible == '1'}
{content block='header'}
{content}
{else}
<div class="bigerror">Private Content. Authorization Required</div>
{/if}
I added public_ to all of my public pages and ambassadors_ to my private page as stated below. Where again ambassadors is my group with the one test user I have created. The public pages show up in my menu and the private page is hidden from the menu when I am not logged in. However, when logged in the private page does not show up in my menu but the public pages still do.
5. Adjust the page alias of all of your pages as follows:
Pages that anonymous/non logged in people can see should start with public_
Pages that only members of group1 can see should begin with group1_ (change group1 to your group name of course)
Similarly, pages that only members of group2 can see should begin with group2_
Conclusion:
Now, the menu should appear properly for anonymous users as well as for members of group1 and/or group2. Also, anybody directly accessing a page their not entitled to see, should get the 'Authorization Required' message.
This solution should work for any number of groups, with menu. I hope this helps everybody.
Any help on this would be greatly appreciated. I think I have posted every thing I need to, if not please let me know and I will post it immediately. Thanks