[support] Dynamically display menu items?

Joel Willers joel.willers at sigler.com
Tue Jun 7 18:59:55 UTC 2011


For your PHP suggestion, you would use global $user and detect the user role, but you wouldn't be able to easily use this for detecting if they have a project.

For my suggestion, you can use the content type Project (I don't know your configuration, so I'm making some general assumptions), and let's say it has a user reference called field_project_user.  You would set that as an argument, and in the section for what to do if there is no argument, you set a default argument as logged in user.  Then you set a filter for node:type = Project.

If there is no project for that user, then the View doesn't fire, so you create the menu in Empty Text area.  So one menu could be in Global:custom text, and the other in Empty Text.

Similar arguments can be used for many user fields, so play around with them.  If you give me more specifics, I might be able to send you more explanation, but really, that should be enough for you to create it.

Joel 


Hey Joel, thank you so much!
I think i could do it if i would be able to load the currently logged in user in the "Show if the following PHP code returns TRUE" box of the menu block. Can i do that? How?

Alternatively, could you elaborate a bit on your last suggestion please?

Best,

Toon


If it were me, I'd use Views and detect the User based on role and probably use Custom Field module for PHP and do all sorts of tests in there.  Since it's a block, though, arguments aren't passed, so you could do a Default argument from PHP and do all sorts of fun PHP code in there, so you wouldn't need an additional module.

Or you could assign a role using a Rule, or have the User based on an argument (again, default argument, Current Logged in User), and use Empty Text to show a different menu based on the existence of that project.

Actually, I kinda like that last idea...

Joel


You could make two blocks, put them in the same place and assign visibility settings based on role.  There are many options, though.

Joel


Hello all,

Let's i want to display or not display a menu item depending on some property of the logged in user. E.g. when my user has selected a project (i.e. a reference to the project can be found through the user) i want to display a menu item "my project", if not i want to display a different menu item "available projects". How do i do this? Context? Rules? Menu hooks?

Any ideas?

Best,


Toon


More information about the support mailing list