[answered] menu content based on page template?

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
jpa
Forum Members
Forum Members
Posts: 14
Joined: Wed Jun 17, 2009 11:31 am

[answered] menu content based on page template?

Post by jpa »

I've used this forum a lot, and usually I've searched and found what I was looking for (thank you :) ), but not this time.

I have a web page where different Frontendusers will have access to different pages.
The menus must then output different items based on the logged in user's name or group.

MenuManager (v. 1.5.3) has a function called "includeprefix", that will only output menu items with page aliases that begins with this prefix.
But for this to work fine, the person that edit the pages must be very careful to put the correct prefix on all the page aliases.

I was looking for a more "water proof" solution.

Is it possible to output menu items based on the page template the pages are using?

Then I can make one page template for each usergroup, and it will be very easy for the person who edits these pages, to choose the correct access for every page. it's easier to select access type within a drop list, than it is to remember to write the correct prefix for this access.

If this is not possible, the includeprefix function will do the trick for now.

I hope my question was understandable.
Thank you.

jpa
Last edited by jpa on Thu Jun 18, 2009 11:19 am, edited 1 time in total.
CMS version: 1.5
Apache/2.2.8 (Ubuntu) DAV/2 SVN/1.5.1 PHP/5.2.4-2ubuntu5.6 with Suhosin-Patch mod_ssl/2.2.8 OpenSSL/0.9.8g
Linux 2.6.24-22-server On i686
NaN

Re: menu content based on page template?

Post by NaN »

Hi Jpa,

finally welcome to the forum. ;)

Not sure if this is what you're looking for but here i tried to explain how to create user specific content very easy:

http://forum.cmsmadesimple.org/index.ph ... #msg161318

It does not depend on the template but just on the page structure.
Your editor don't select a group specific template but a group specific parent page.
So you will have a good overview what pages belong to what groups by just viewing the page hierarchy.
jpa
Forum Members
Forum Members
Posts: 14
Joined: Wed Jun 17, 2009 11:31 am

Re: menu content based on page template?

Post by jpa »

NaN wrote:
Hi Jpa,

finally welcome to the forum. ;)

Not sure if this is what you're looking for but here i tried to explain how to create user specific content very easy:
Thanks for the welcome :)

Not really, but your tip reminded me of another thing I had to solve.
To use different content blocks solves the problem where two users shall have different content on the same page.

My question was about totally hiding the pages in the menu from one user but not for the other.
CMS version: 1.5
Apache/2.2.8 (Ubuntu) DAV/2 SVN/1.5.1 PHP/5.2.4-2ubuntu5.6 with Suhosin-Patch mod_ssl/2.2.8 OpenSSL/0.9.8g
Linux 2.6.24-22-server On i686
Jeff
Power Poster
Power Poster
Posts: 961
Joined: Mon Jan 21, 2008 5:51 pm

Re: menu content based on page template?

Post by Jeff »

no, you don't have easy access to the template used when creating the menu.

I setup my menu to check for the word 'private' in the extra1 field ($node->extra1) and only display it if the user is logged in.
jpa
Forum Members
Forum Members
Posts: 14
Joined: Wed Jun 17, 2009 11:31 am

Re: menu content based on page template?

Post by jpa »

ajprog wrote: no, you don't have easy access to the template used when creating the menu.

I setup my menu to check for the word 'private' in the extra1 field ($node->extra1) and only display it if the user is logged in.
Thank you.
That might be a better solution than to use includeprefix. I'll try it out.
CMS version: 1.5
Apache/2.2.8 (Ubuntu) DAV/2 SVN/1.5.1 PHP/5.2.4-2ubuntu5.6 with Suhosin-Patch mod_ssl/2.2.8 OpenSSL/0.9.8g
Linux 2.6.24-22-server On i686
jpa
Forum Members
Forum Members
Posts: 14
Joined: Wed Jun 17, 2009 11:31 am

Re: menu content based on page template?

Post by jpa »

ajprog wrote: no, you don't have easy access to the template used when creating the menu.

I setup my menu to check for the word 'private' in the extra1 field ($node->extra1) and only display it if the user is logged in.
Sorry, but where in the menu template do you check for the extra field?

[EDIT: wait, I found out on my own  8)]
Last edited by jpa on Thu Jun 18, 2009 1:07 pm, edited 1 time in total.
CMS version: 1.5
Apache/2.2.8 (Ubuntu) DAV/2 SVN/1.5.1 PHP/5.2.4-2ubuntu5.6 with Suhosin-Patch mod_ssl/2.2.8 OpenSSL/0.9.8g
Linux 2.6.24-22-server On i686
jmcgin51
Power Poster
Power Poster
Posts: 1899
Joined: Mon Jun 12, 2006 9:02 pm

Re: [answered] menu content based on page template?

Post by jmcgin51 »

jpa wrote: Sorry, but where in the menu template do you check for the extra field?

[EDIT: wait, I found out on my own  8)]
for the benefit of those who might not be able to decipher the menu template so easily...

This:
{foreach from=$nodelist item=node}
{if $node->extra1 != 'private'}

{/if}
{/foreach}
will give you a menu that checks the extra1 page attribute for each active page, and if the word "private" is entered, the page will not be displayed in the menu.

If you do this instead (as I did my first time):
{if $node->type != 'sectionheader' and $node->type != 'separator' and $node->extra1 != 'private'}
it will still hide the page, but the page's place in the menu will still be held.  In other words, if your full unedited menu is
Home    PrivatePage    About    Contact

the first solution above will give you
Home    About    Contact

but the second solution will give you
Home                        About    Contact

For most, the first solution is preferable.
jpa
Forum Members
Forum Members
Posts: 14
Joined: Wed Jun 17, 2009 11:31 am

Re: [answered] menu content based on page template?

Post by jpa »

jmcgin51 wrote:
jpa wrote: Sorry, but where in the menu template do you check for the extra field?

[EDIT: wait, I found out on my own  8)]
for the benefit of those who might not be able to decipher the menu template so easily...
I did not have the time to post what I did earlier, but did not want anyone to spend time in vain on a post to help.

Here's what I did:

I have four user types in a hierarchical system. User type 1 has the least access. User type 2 have access to the same pages as no 1, plus some pages. User type 3 have access to all the pages user type 2 have access to, plus some more pages. And user type 4 have access to all pages.

User type 4 can use a standard menu template.

For the other three, I invented a "code" in the extra1 field, like "123".
Pages for user type 1 and up have extra1 = "123"
Pages for user type 2 and up have extra1 = "12"
Pages for user type 3 and up have extra1 = "1"

Then I created one menu template for each user type, and used truncate to differ.
I added this to all the main "if"s in the template because it must apply to all meny items

One smarty example for user type 2:

Code: Select all

{if $node->extra1|truncate:2:"" eq '12'}
When user type 2 logs in, he has now access to all pages with extra1 that begins with "12", also "123", but he has not access to pages where extra1 = "1".

My colleague also modified the edit content page so that the extra1 field now is a drop list with the four options instead of a free text field. I don't know how he did that :)
CMS version: 1.5
Apache/2.2.8 (Ubuntu) DAV/2 SVN/1.5.1 PHP/5.2.4-2ubuntu5.6 with Suhosin-Patch mod_ssl/2.2.8 OpenSSL/0.9.8g
Linux 2.6.24-22-server On i686
jmcgin51
Power Poster
Power Poster
Posts: 1899
Joined: Mon Jun 12, 2006 9:02 pm

Re: [answered] menu content based on page template?

Post by jmcgin51 »

Thanks for posting the details!
jpa wrote: My colleague also modified the edit content page so that the extra1 field now is a drop list with the four options instead of a free text field. I don't know how he did that :)
Yes, this would be nice.  Or alternatively a checkbox (private if TRUE (checked), public if FALSE)
NaN

Re: [answered] menu content based on page template?

Post by NaN »

To get custom fields of any type you want you could try this modified contenttype:

http://forum.cmsmadesimple.org/index.ph ... #msg161354

But notice that the contentypes will change a bit in CMSms 1.6.
So this idea wont work anymore in future releases.
Last edited by NaN on Thu Jun 25, 2009 4:58 pm, edited 1 time in total.
Post Reply

Return to “Modules/Add-Ons”