Page 1 of 1

[RESOLVED] 2 menus

Posted: Mon Oct 28, 2013 10:58 am
by eddyR3
Hi guys, hope you are well.

I have a site that needs 2 menus....

Main menu, which is a left hand navigation which displays all parent pages, which is working as it should and fine.

But then i have some sub menu pages, where i need a menu in the middle (which ive designed/styled) but only needs to display child menu items from specific areas.

Is there a way i can setup the menus with different names to only use items within its parent category?

For example :
/*All templates use Menu 0 as left navigation */

Template 1 uses Menu 1 and displays menu items from Parent 1

Template 2 uses Menu 1 and displays menu items from Parent 2

Template 3 uses Menu 1 and displays menu items from Parent 3

/*None of the children are to be displays on Menu 0*/

Hopefully that makes some sense! :)

Any advice, suggestions would be great! :)

Re: 2 menus

Posted: Mon Oct 28, 2013 12:08 pm
by rotezecke
not sure i understand what you mean but here's a snippet out of a UDT that checks for template ID and hierarchy before loading a menu.

Code: Select all

$contentops = cmsms()->GetContentOperations();
$content_obj = $contentops->getContentObject();
$hierarchy = explode('.',$content_obj->Hierarchy());
$template = $content_obj->TemplateId();
$pageLevel = count($hierarchy);
//$smarty = cmsms()->GetSmarty(); 
// $smarty->assign('templateId', $template); 
if($pageLevel >= 2 && ($template == 27 || $template == 36)) {
  $parentPage = $hierarchy[0] .'.'.$hierarchy[1];
  $smarty_data = "{menu template='side_menu' start_element=\"$parentPage\" loadprops=0}";
} elseif($pageLevel >= 2 && $template != 27 && $template != 36) {
  $parentPage = $hierarchy[0] .'.'.$hierarchy[1];
  $smarty_data = "{menu template='gallery_menu' start_element=\"$parentPage\" loadprops=0}";
} elseif($template == 27 || $template == 36) {
  $smarty_data = "{makeTabs tab_one=\"$tab1\" tab_two=\"$tab2\" tab_three=\"$tab3\" tab_four=\"$tab4\" tab_five=\"$tab5\" tab_six=\"$tab6\" tab_seven=\"$tab7\" tab_eight=\"$tab8\" tab_nine=\"$tab9\" tab_ten=\"$tab10\"}";
} else {
  $smarty_data = "{menu template='gallery_menu' start_page=\"$content_obj->Alias()\" loadprops=0 show_all=0}";
}
echo $smarty->display('string:'.$smarty_data);

Re: 2 menus

Posted: Mon Oct 28, 2013 12:19 pm
by eddyR3
Perhaps some links will help :)

This page displays 2 menus (or at least will if possible) :

http://e-cig-reviews.com/index.php?page=e-pipes

The left hand nav (main nav) and links in the middle content area.

Its the links in the middle content area im struggling with.

Each item in the main nav is just a parent, and each parent will have "children" which i need displaying on each of the sub pages.

For example, if "E-Pipes" has 3 items as children :

Option 1
Option 2
Option 3

Then those pages will display on the "E-Pipes" menu (in the middle content)

Then, if you goto E-Cigars then the menu in the middle would change to show the Children pages of E-Cigars...

Hope that makes a bit more sense?

Many thanks for the reply! :)

Re: 2 menus

Posted: Mon Oct 28, 2013 12:31 pm
by rotezecke
from menu help:
(optional) childrenof="" - This option will have the menu only display items that are descendants of the selected page id or alias. i.e: {menu childrenof=$page_alias} will only display the children of the current page.

Re: 2 menus

Posted: Mon Oct 28, 2013 12:34 pm
by eddyR3
I should read more shouldnt i? lol

Thankyou very much for your help! Ill see how i get on :D

Re: 2 menus

Posted: Mon Oct 28, 2013 12:46 pm
by velden
Snippet of code from a website I made. No children_of but start_level:

Code: Select all

 {menu number_of_levels="1"}
	</div>
	<div id="main">
	  <div id="left" class="column">
	     {capture assign="submenu"}{menu template="sg_submenu" number_of_levels="1" start_level="2"}{/capture}
		 {if !empty($submenu)}
		   {$submenu}
		 {else} ...
Main menu is displayed, only one level. Then if a submenu exists for the current page, it is displayed (start_level="2").
I use the 'number_of_levels="1"' in the submenu to prevent the menu from getting f*cked up because of an editor adding subpages too deep.

Further, the {capture} tag is said to be inefficient and it's better to use the 'assign' parameter of {menu}. But hey, don't fix what's not broken...

Re: [RESOLVED] 2 menus

Posted: Mon Oct 28, 2013 3:54 pm
by eddyR3
Excellent thanks guys, its all really helped! :D

Sorted.