Page 1 of 1

[SOLVED] Keep failing to implement menu that lists siblings of any given page

Posted: Tue Dec 15, 2009 9:22 pm
by AlejandroCM
I am trying to get a menu that will list the siblings of any 3rd level page so I can use one template for all.

Currently I am using this :

{menu template='minimal' start_element='X.1.1' show_root_siblings='1'} where X is an integer from 1 to 5.

but the problem with it is that I have to create different templates for pages 3.1.1, 4.1.1, 5.1.1 and so on, which beats the purpose of a template!

I managed to find this in the documentation:

tag name: {hierarchy}

which is defined as:

global $gCms;
$pos = $gCms->variables['position'];
$base = explode('.', $pos);
$smarty->assign('h_toplevel', $base[0] * 1);
$smarty->assign('h_parent',   $base[ (count($base) > 1) ? count($base)-2 : 0 ] * 1);
$smarty->assign('h_this',     $base[count($base)-1] * 1);

and have applied it on this page: http://2294057.2288230.test.prositehost ... ng-systems
as such :

{hierarchy}
{cms_module module='menumanager' start_element=$h_this template='minimal' collapse='0'}

The documentation says that if I want to display the siblings of the page I have to use $h_this. But this outputs just Home which isn't even the grandparent of this page. I tried h_parent and h_toplevel and they all return Home

Am I doing something wrong?

Thanks in advance.

[UPDATE] It occurred to me that this might not be the right category to post this as the UDT I refer to above is not part of the CORE. My apologies to the administrators if that is the case.

---------------------------------------
CMS Version 1.6.5
MenuManager 1.6.2
Current PHP Version (phpversion): 5.1.6

Re: Keep failing to implement menu that lists siblings of any given page

Posted: Tue Dec 15, 2009 10:06 pm
by Dr.CSS
When you say "list the siblings of any 3rd level page" is this a 3rd level page you are on or ?...

Re: Keep failing to implement menu that lists siblings of any given page

Posted: Tue Dec 15, 2009 10:22 pm
by AlejandroCM
I have:

TOP LEVEL: Industrial
Child of Industrial: Thermal Processing
Child of Thermal Processing: Drying Systems

which is [link removed]

I need this page (which I thought was 3rd level / correct me if I am wrong ) to have a submenu that lists the page in question alongside its siblings.

So submenu will be:

Drying Systems  |  Curing Systems  |  Heat Treatment Systems

As you can see on the link above, it currently just displays Home even though I  use $h_this like so:

{hierarchy}
{cms_module module='menumanager' start_element=$h_this template='minimal' collapse='0'}

If you go to [link removed] you will see what I'm trying to achieve. Although it may appear that the menu works right on this page it is not as I'm specifically telling it to start at level 5.1.1 which of course will display the wrong items if I am at a child of 3 or 4 etc.

Re: Keep failing to implement menu that lists siblings of any given page

Posted: Thu Dec 17, 2009 5:38 pm
by Dr.CSS
Looks like it works now...

There are parameters like start_level='3'...

Re: Keep failing to implement menu that lists siblings of any given page

Posted: Thu Dec 17, 2009 5:54 pm
by AlejandroCM
Hi Mark and thanks for replying.

It only appears to be working where in fact it is not. This is the tag I am using --> {menu template='minimal' start_level='4.1.1' show_root_siblings='1'}

As you can see if I go to 4.2.1 then I will still see the siblings of 4.1.1. Same for 4.3.1 and 5.1.1, 5.2.1 and 5.3.1.
This means that in order to achieve the effect I am after I would have to create a different template for every single page.

This would of course beat the point of having a template! :(

It occurs to me that {hierarchy} (as mentioned on above posts) is the way to go but no matter what I use ($h_this, $h_parent, h_toplevel) I get the same result, which is Home.

thanks

P.S. It's a little hard to believe nobody else has had the need to create a menu that lists the siblings of any given page when one is viewing the said page. All my searches are in vain and even google returns just this post as the only relevant result. Been at it for days now with all sorts of different search strings. I think I'm gonna ask santa next :) hehe

Re: Keep failing to implement menu that lists siblings of any given page

Posted: Mon Jan 11, 2010 9:16 am
by AlejandroCM
No one? help?  :( I'm in a tight spot right now as deadline is this week and I truly cannot afford to pay a dev!

thanks

Re: Keep failing to implement menu that lists siblings of any given page

Posted: Mon Jan 11, 2010 6:01 pm
by Dr.CSS
Have you tried the start_level='3' without the siblings call...

Re: Keep failing to implement menu that lists siblings of any given page

Posted: Tue Jan 12, 2010 4:52 pm
by AlejandroCM
Yep I have.

{menu template='minimal' start_level='3' }

This returns a fully expanded menu listing everything under 3.

e.g.

3.1
3.1.1
3.1.2
3.1.3
3.2
3.2.1
3.2.2
3.2.3
3.3
3.3.1
3.3.2
3.3.3

What I need is:

When on 3.1.1, the submenu should display:

3.1.1
3.1.2
3.1.3

When on 3.2.1, the submenu should display:

3.2.1
3.2.2
3.2.3

and so on.

Currently the only way I can make this work is if I make a template for 3.1.1, 3.1.2, 3.1.3 using {menu template='minimal' start_level='3.1' } another for 3.2.1, 3.2.2, 3.2.3 using {menu template='minimal' start_level='3.2' } and another for 3.3.1, 3.3.2, 3.3.3 using {menu template='minimal' start_level='3.3' }.

The way I see it this is totally against the point of templates and would make it very hard for someone editing the site to actually pick a template from the list when creating a new page as there would be tens of them. Not to mention that a new template would need creating if they decide to add a 3.4 section.

Thoughts?

many thanks

Re: Keep failing to implement menu that lists siblings of any given page

Posted: Tue Jan 12, 2010 9:56 pm
by AlejandroCM
I'm starting to feel rather stupid now....like I'm missing the obvious!  :(

Re: Keep failing to implement menu that lists siblings of any given page

Posted: Tue Jan 12, 2010 10:47 pm
by Dr.CSS
Maybe you need to use start level 4 as it seems those are 4th level menu items, I would just keep changing start levels till  it worked ;)...

Re: Keep failing to implement menu that lists siblings of any given page

Posted: Wed Jan 13, 2010 7:01 pm
by AlejandroCM
I have already tried this Mark but it returns absolutely nothing.....

tried with 1,2,3,4,5,6 and it always returns nothing...the space is totally blank. This is the confusion you see.

{cms_module module='menumanager' start_level='4' template='minimal' }

Re: Keep failing to implement menu that lists siblings of any given page

Posted: Sat Feb 27, 2010 11:55 am
by AlejandroCM
Hi again,

In the end I had to pay a dev to solve this for me.
Here is the solution:


Created a new UDT called 'menutext' and added this code to it:

----------------------------------------------------------
global $gCms;
global $smarty;

$manager =& $gCms->GetHierarchyManager();

$var = 'parent_page_menutext';
if( isset($params['assign']) && $params['assign'] != '' )
{
  $var = $params['assign'];
}
$result = "NO RESULT";
$thisPage = $gCms->variables['content_id'];
$currentNode = &$manager->sureGetNodeById($thisPage);
while( isset($currentNode) && $currentNode->getLevel() >= 1 )
{
    $currentContent =& $currentNode->getContent();
    $result = $currentContent->menutext();
    $currentNode =& $currentNode->getParentNode();
}
$smarty->assign($var,$result);

--------------------------------------------------------



then in my template, wherever I want to add the menu I put this code:


{foreach from=$nodelist item=node}{if $node->current == true}{menu template='minimal' start_element=$node->hierarchy show_root_siblings='1'}{/if}{/foreach}


This produces a sidemenu listing the current page and its siblings while still keeping the top menu template with full expandability.

Hope this helped someone with the same problem.

:)