Conditional menu behavior in Drupal

I added some code to the page.tpl.php to change the behavior of the elearning page on ODT for logged in vs anonymous viewers.

path=="elearning"){?>
    $(document).ready(function() {
uid) {?>
				$('.expanded').each( function(){Drupal.dhtmlMenu.toggleMenu($(this));}); //Close all
				Drupal.dhtmlMenu.toggleMenu($('#skillport-login')); //Open login button section

				$('.collapsed').each( function(){Drupal.dhtmlMenu.toggleMenu($(this));}); //Open all

		});
		

  1. Check if the page is elearning ($node->path)
  2. Check if the viewer is logged in or not
    • If so, collapse all sections but expand the log in button section
    • If not then expand all the sections so the user will be encouraged to read the substantive content.

Thanks to Janie, here in HR for the suggestion.

Notes:
I’ve read that it’s not ideal to add conditional statements to the template and a bit about drupal_add_js and but other methods weren’t working so that how we’re accomplishing this for now.

Comments
  • Vid says:

    I’ve recently enabled php input and replaced our TinyMCE module with wysiwyg module with TinyMCE enabled. Which behaves much better with php and drupal_add_js so I revisited the idea of putting this code in the page body; but my concern is that other administrators who don’t have php access can’t edit the post and if they could they wouldn’t want to view it in code view.

    So I’ll have to do some testing with different permission before we move forward with that, but it would be nice to get this out of the template.

    In addition some users are irked by having all their menus fly open or closed when they refresh the page. So testing for certain cookies first may be the best this to do here.

Leave a Comment