[SOLVED] CustomContent, MenuManager, page aliases and user groups in combination

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
Andor
Forum Members
Forum Members
Posts: 49
Joined: Sun Feb 19, 2006 1:42 pm

[SOLVED] CustomContent, MenuManager, page aliases and user groups in combination

Post by Andor »

Hi,

I have been using CustomContent and MenuManager in combination for a while, e.g.

Code: Select all

{if isset($customcontent_loggedin) && $customcontent_loggedin > 0}
{cms_module module='menumanager' template='fjs_horiz'  number_of_levels='1'  excludeprefix='std_'}
{else}
{cms_module module='menumanager' template='fjs_horiz'  number_of_levels='1' excludeprefix='priv_'}
{/if}
Yesterday I found out how to change background images based on parent aliases - exciting!

Now I would like to combine these two insights and with 50 different user groups, I don't want to go excludeprefix or includeprefix for 49 group prefixes or do several nested 'if' statements.

My idea is to read the user group of the logged-in user and use that in place of the 'std_' and 'priv_' above, i.e. smarty inside smarty and then use includeprefix based on the user group.

Any ideas on how that should be done?

Thanks in advance
Last edited by Andor on Thu Nov 20, 2008 12:48 pm, edited 1 time in total.
Andor
Forum Members
Forum Members
Posts: 49
Joined: Sun Feb 19, 2006 1:42 pm

Re: CustomContent, MenuManager, page aliases and user groups in combination

Post by Andor »

Ok, after a good night's sleep I found a solution - funny how the brain continues to work when sleeping ;)

I put the following lines in the template

Code: Select all

{if isset($customcontent_loggedin) && $customcontent_loggedin > 0}
{cms_module module='menumanager' template='fjs_horiz'  number_of_levels='1' includeprefix=$customcontent_groups}
{else}
{cms_module module='menumanager' template='fjs_horiz'  number_of_levels='1' includeprefix='gen_'}
{/if}
The 'includeprefix=$customcontent_groups' was the solution I initially was looking for. I assign frontend users to two groups: 'gen_' and one user specific group with a name like '24_' .

In this case the user will always see the general menus and content as long as I change the general content page aliases to include a 'gen_' prefix. The rest of the page aliases will include frontend user group specific prefixes, e.g. '24_' and will be shown when the user is logged in - a user that now belongs to two groups: gen_ and xx_  and therefore will see both the general and the user group specific menus and pages.

If you have other and more effective solutions for this one, please share...

Now, my next challenge is to get the

Code: Select all

{if $ccuser->loggedin()}
(content)
out from the editors pages and in to the template  - there will be approx. 50 editors; one for each group...

Still learning :)
oyeindia
New Member
New Member
Posts: 5
Joined: Sat Apr 12, 2008 8:52 am

Re: [SOLVED] CustomContent, MenuManager, page aliases and user groups in combination

Post by oyeindia »

Andor:

I wonder if you could explain your initial method to me a bit more. I'm trying to build a site where the visitor sees only an "About Us" page and a "Register Now" page, and once registered and logged in, the visitor can see all the menus and pages.

I tried following CalGuy's method in a forum post that involved ordering menus under, say, "Public" and "Private" heads, but must have done something wrong, because that didn't work for me.

TIA,

Oye
Andor
Forum Members
Forum Members
Posts: 49
Joined: Sun Feb 19, 2006 1:42 pm

Re: [SOLVED] CustomContent, MenuManager, page aliases and user groups in combination

Post by Andor »

Hi there,

My initial method handled several user groups and used the 'includeprefix=$customcontent_groups' part to pull the logged in users's group(s) and match this to pages with corresponding alias prefixes.

You will need to adjust all page aliases (just the prefix) and user groups to match each other, i.e. user groups like group01_, group02_ and page aliases like group01_private_content, group01_even_more_private and group02_really_secret.

In your case it should be easier. As I understand it you just have two user groups: 1) Logged in  2) Not logged in. You won't need to add the 'groups_to_prefixes' UDT and with just the two public pages you may even use the aliases for those, without a specific prefix.

Anway, you will have to fix the template for both the menu and the content:

An example for a top level menu

Code: Select all

{if $customcontent_loggedin > 0}
	{cms_module module='menumanager' template='your_template'  number_of_levels='1' includeprefix='about,register,priv_'}
{else}
	{cms_module module='menumanager' template='your_template'  number_of_levels='1' includeprefix='about,register'}
{/if}
You may also go excludeprefix='priv_' instead of the second includeprefix.

If you use a menu setup with top level and the rest in a sub menu, you would have to do the same thing for the sub menu and use standard syntax, e.g. start_level='2' collapse='1' in the menu call.

As I mentioned, the example above will not handle different user groups; just logged in and not logged in. If you would like to add that functionality, CalGuy's way is indeed a good one - I use it myself.


The content
Now, you need to adjust the template for the content part of it all. I suggest you go for CalGuy's solution: adjusting the template, the optional metadata field for each private page and the alias for each private page. In your case, you probably want to adjust the code for the metadata field a bit compared to the original, since you don't need to check for specific user groups.

The private pages optional metadata field:

Code: Select all

{assign var='content_is_visible' value='0'}
{if $customcontent_loggedin > 0}
       {assign var='content_is_visible' value='1'}
{/if}
You also need to change all private page aliases to include the prefix 'priv_'.

Use CalGuy's method for the template:

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'}
	<h1>{title}</h1>
	{content}
{else}
	<div class="bigerror">You need to log in...</div>
{/if}
Don't forget to style the 'bigerror' in your CSS ;)

The disadvantage of having to add the code lines to the metadata field in all private pages could be handled by using two content blocks in the template instead - one for public and the other for private content. You could even use two templates - one for the public pages where the {content} is just inserted as it is and the other for the private pages where the {content} is handled with custom content module standards:

Code: Select all

{if $customcontent_loggedin > 0}
	{content}
{else}
	<h1>You are not authorized to view this data</h1>
{/if}
CalGuy's method is based on just one template, which of course is effective as it let you forget about adjusting two templates when updating it.

I guess it's just a matter of taste and by whom the site will be managed - you or an editor. Personally, if the content  will be updated by an editor, without knowledge about the tech stuff, I would go for two templates.

Good luck and please let me know if you get it to work as you want.

Happy holidays :)
Post Reply

Return to “CMSMS Core”