Only show submenu when parent page is active?

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
jmansa
Forum Members
Forum Members
Posts: 126
Joined: Thu Oct 19, 2006 2:46 pm

Only show submenu when parent page is active?

Post by jmansa »

I'm trying to figure out how to make an only subpages menu when the parent page is active... Can anybody guide me in the right direction... Tutorial etc...
gdur
Forum Members
Forum Members
Posts: 142
Joined: Sun Jan 10, 2010 10:59 am

Re: Only show submenu when parent page is active?

Post by gdur »

Hi Jmansma,

Have a look at the submenu at the left site of the page at www.duran-audio.com.
Is this what you are looking for?
RonnyK
Support Guru
Support Guru
Posts: 4962
Joined: Wed Oct 25, 2006 8:29 pm
Location: Raalte, the Netherlands

Re: Only show submenu when parent page is active?

Post by RonnyK »

If your parent pages are level 1, then you can call the second menu with start_level=2. So only when a parent is selected ITS children will show then...

Ronny
jmansa
Forum Members
Forum Members
Posts: 126
Joined: Thu Oct 19, 2006 2:46 pm

Re: Only show submenu when parent page is active?

Post by jmansa »

gdur wrote: Hi Jmansma,

Have a look at the submenu at the left site of the page at www.duran-audio.com.
Is this what you are looking for?
That is exactly what I am looking for...
gdur
Forum Members
Forum Members
Posts: 142
Joined: Sun Jan 10, 2010 10:59 am

Re: Only show submenu when parent page is active?

Post by gdur »

OK here is the code

Code: Select all

{get_page_depth assign="depth"}
{get_parent_page_alias assign="parent" page=$title}
{get_page_menutext assign="parent_menutext" page=$parent}
{assign var="level" value=$depth}
{if $count > 0}
{foreach from=$nodelist item=node}
{if $node->current == true && $node->depth == 2 && $node->haschildren == false}
{assign var="level" value=0}
{/if}
{/foreach}
{/if}


{if $level ==2}
<ul class="menu_vert">
   <li><a href="?page={$parent}">{$parent_menutext}</a></li>
{/if}

{if $depth == 2}
{assign var="depth" value="-2"}
{assign var="depthcheck" value="0"}

{if $count > 0}
{foreach from=$nodelist item=node}
{if $node->index == 0}
{elseif $node->haschildren == false }
{/if}
          {if $depthcheck == 1 && $node->depth != $node->prevdepth}

             {assign var="depth" value=$node->depth}
             {assign var="depthcheck" value="0"}
             {assign var="listopened" value="1"}
         {/if}
{if $node->depth == $depth}
 <li>
 <a href="{$node->url}"{if $node->target ne ""} target="{$node->target}"{/if}>{$node->menutext}</a><br />
        </li>
         {/if}
{if $node->current == true &&  $node->haschildren == true}

<li>
{* This is the current page of level 2, strong no link *}
<a {*href="{$node->url}"*}{if $node->target ne ""} target="{$node->target}"{/if}><strong>{$node->menutext}</strong></a><br /></li>
        {assign var="depthcheck" value="1"}
{/if}
{/foreach}
       {if $listopened == 1}
      </ul>
      {/if}
      {/if}
{/if}

{if $level > 2}
{assign var="startshowing" value="0"}
{assign var="stopshowing" value="0"}
{if $count > 0}

{foreach from=$nodelist item=node}
{if $startshowing == 1 }
<ul class="menu_vert">
<li>
{* this is the parent page, first in the list, of level 3*}
<a href="{$node->url}"{if $node->target ne ""} target="{$node->target}"{/if}>{$node->menutext}</a><br />
</li>
{assign var="startshowing" value=$startshowing+1}
{/if}

{if $node->parent == true}
{assign var="passed" value="true"}
{assign var="nodedept" value=$node->depth+1}
{assign var="startshowing" value=$startshowing+1}
{elseif $node->depth == $nodedept && $passed == true}
{if $node->current == true}
<li>
{* This is the current page, displayed bold, of level 3*}
<a{if $node->target ne ""} target="{$node->target}"{/if}><strong>{$node->menutext}</strong> </a><br />
</li>
{else}
<li>
{* These are the level 3 pages *}
<a href="{$node->url}"{if $node->target ne ""} target="{$node->target}"{/if}>{$node->menutext}</a><br />
</li>
{/if}
{assign var="stopshowing" value="0"}
 
{/if}
{/foreach}
</ul>
{/if}
{/if}

{if $level < 2}
{assign var="firstsub" value="1"}
  {assign var="depth" value="-2"}
  {assign var="depthcheck" value="0"}
  {assign var="listopened" value="0"}
  {if $count > 0}
  {foreach from=$nodelist item=node}
  {if $node->index == 0}
  {assign var="icon" value="house"}
  {elseif $node->haschildren == true }
  {assign var="icon" value="folder"}
  {elseif $node->haschildren == false }
  {assign var="icon" value="page"}
  {/if}
  {if $depthcheck == 1 && $node->depth != $node->prevdepth}
  <ul class="menu_vert">
  {assign var="depth" value=$node->depth}
  {assign var="depthcheck" value="0"}
  {assign var="listopened" value="1"}
  {/if}
  {if $node->depth == $depth && $firstsub == 1}
  <li style="list-style-image: url('images/icons/{$icon}.png') ">
{* These are the level 1 pages *}
  <a href="{$node->url}"{if $node->target ne ""} target="{$node->target}"{/if}>{$node->menutext}</a><br />
  {$node->titleattribute}</li>
  {elseif $listopened == 1}
  {assign var="firstsub" value="0"}
  {/if}
  {if $node->current == true &&  $node->haschildren == true}
  {assign var="depthcheck" value="1"}
  {/if}
  {/foreach}
  {if $listopened == 1}
  </ul>
  {/if}
  {/if}
{/if}

{if $level == 0}
{assign var="firstsub" value="1"}
  {assign var="depth" value="-2"}
  {assign var="depthcheck" value="0"}
  {assign var="listopened" value="0"}
  {if $count > 0}
  {foreach from=$nodelist item=node}
  {if $node->index == 0}
  {assign var="icon" value="house"}
  {elseif $node->haschildren == true }
  {assign var="icon" value="folder"}
  {elseif $node->haschildren == false }
  {assign var="icon" value="page"}
  {/if}
  {if $depthcheck == 1 && $node->depth != $node->prevdepth}
  <ul class="menu_vert">
  {assign var="depth" value=$node->depth}
  {assign var="depthcheck" value="0"}
  {assign var="listopened" value="1"}
  {/if}
  {if $node->depth == $depth && $firstsub == 1}
  
{if $node->current == true}
<li>
<a href="{$node->url}"{if $node->target ne ""} target="{$node->target}"{/if}><strong>{$node->menutext}</strong> </a><br />
</li>
{else}
<li>
<a href="{$node->url}"{if $node->target ne ""} target="{$node->target}"{/if}>{$node->menutext}</a><br />
</li>
{/if}
  {elseif $listopened == 1}
  {assign var="firstsub" value="0"}
  {/if}
  {if $node->parent == true &&  $node->haschildren == true}
  {assign var="depthcheck" value="1"}
  {/if}
  {/foreach}
  {if $listopened == 1}
  </ul>
  {/if}
  {/if}
{/if}
The code isn't clean at all but it works and I'm a kind of lazy...
Use Menu Manager to add a new template and just call it in your page template where you want the submenu to appear.
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am
Location: Arizona

Re: Only show submenu when parent page is active?

Post by Dr.CSS »

@gdur

There is no need to do all that just do like the default temples do it...

http://multiintech.com/defaultcontent/i ... e=top_left
gdur
Forum Members
Forum Members
Posts: 142
Joined: Sun Jan 10, 2010 10:59 am

Re: Only show submenu when parent page is active?

Post by gdur »

@Dr.CSS

I'm sorry but that's just not the same! I guess you have missed the objectives here.
This approach keeps track on where you are. When there are child pages it shows these in the submenu. When your down 1 or more levels it also shows the parent pages and when you're at the lowest level it shows the sister pages. This menu addepts itself depending on what level you are plus it also highlights the current page.
The convenience is that if there are a lot of sister pages (i.e. various models of a product group) the visitor can quickly and easily jump between the different sister pages without the need to dive into the less accessible top pull down menu. Still both remain available. If you want to go totally somewhere else from where you are, you still have quick access through the top menu which remains available at all times.

At the time of getting this to work I've spend weeks to determine the mechanics behind and have tried every available option and example offered and also received some help through this forum.
http://forum.cmsmadesimple.org/index.php/topic,42254.0.html
jmansa
Forum Members
Forum Members
Posts: 126
Joined: Thu Oct 19, 2006 2:46 pm

Re: Only show submenu when parent page is active?

Post by jmansa »

gdur wrote: The code isn't clean at all but it works and I'm a kind of lazy...
Use Menu Manager to add a new template and just call it in your page template where you want the submenu to appear.
I get this error when trying to use the solution?

unrecognized tag 'get_page_depth'
unrecognized tag 'get_parent_page_alias'
unrecognized tag 'get_page_menutext'


Any ideas?!
gdur
Forum Members
Forum Members
Posts: 142
Joined: Sun Jan 10, 2010 10:59 am

Re: Only show submenu when parent page is active?

Post by gdur »

Yeah, sorry some smarties are missing.
Create the following UDT's

get_page_depth

Code: Select all

global $gCms;
global $smarty;

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

if( isset($params['assign']) && $params['assign'] != '' )
{
  $var = $params['assign'];
}

$thisPage = $gCms->variables['content_id'];
$currentNode = &$manager->sureGetNodeById($thisPage);
$result = $currentNode->getLevel() + 1;
if( isset($params['assign']) && $params['assign'] != '' )
{
  $var = $params['assign'];
  $smarty->assign($var,$result);
}
else
{
  return $result;
}
get_page_menutext

Code: Select all

global $gCms;
    $contentops =& $gCms->GetContentOperations();
    $smarty =& $gCms->GetSmarty();

    if( isset($params['page']) )
    {
        $alias = $params['page'];
    }
    else 
      {
	$alias = $smarty->get_template_vars('page_alias');
      }

    $content =& $contentops->LoadContentFromAlias($alias);
    if( !is_object($content) ) return '';

   $text = $content->MenuText();

   if( isset($params['assign']) )
    {
       $smarty->assign($params['assign'],$text);
    }
  else
   {
      return $text;
   }
get_parent_page_alias

Code: Select all

    global $gCms;
    $contentops =& $gCms->GetContentOperations();
    $smarty =& $gCms->GetSmarty();

    if( isset($params['page']) )
    {
        $alias = $params['page'];
    }
    else 
      {
	$alias = $smarty->get_template_vars('page_alias');
      }
    $content =& $contentops->LoadContentFromAlias($alias);
    if( !is_object($content) ) return '';

    $parentid = $content->ParentId();
    if( $parentid != 0 ) 
     {
        $alias = $contentops->GetPageAliasFromId($parentid);
     }
   else
     {
        $alias = '';
     }

   if( isset($params['assign']) )
    {
       $smarty->assign($params['assign'],$alias);
    }
   else
    {
       return $alias;
   }
That should solve...
jmansa
Forum Members
Forum Members
Posts: 126
Joined: Thu Oct 19, 2006 2:46 pm

Re: Only show submenu when parent page is active?

Post by jmansa »

Well, still having trouble... Nothing shows..?

My pages are as follows:

1. Home
  1.1 Profile
  1.2 Info
2. Images
3. Documents
  3.1 Private
  3.2 Public

So as I can see when I am at "Home" the Profile and Info pages should show in my menu right?

Well nothing happens... Any idea?
gdur
Forum Members
Forum Members
Posts: 142
Joined: Sun Jan 10, 2010 10:59 am

Re: Only show submenu when parent page is active?

Post by gdur »

Could you provide a link so I can have a look?
jmansa
Forum Members
Forum Members
Posts: 126
Joined: Thu Oct 19, 2006 2:46 pm

Re: Only show submenu when parent page is active?

Post by jmansa »

gdur
Forum Members
Forum Members
Posts: 142
Joined: Sun Jan 10, 2010 10:59 am

Re: Only show submenu when parent page is active?

Post by gdur »

It appears that you don't call a menu at all in your template but you are calling a javascript instead. The little bit what looks like a menu is commented out in the source code.
jmansa
Forum Members
Forum Members
Posts: 126
Joined: Thu Oct 19, 2006 2:46 pm

Re: Only show submenu when parent page is active?

Post by jmansa »

gdur wrote: It appears that you don't call a menu at all in your template but you are calling a javascript instead. The little bit what looks like a menu is commented out in the source code.
Well, actually... I have the menu within the html like this...

Code: Select all

<div id="back_front">
          	<div id="rightmenu">{menu template="submenu"}</div>
            <div style="padding-right:0px;width:560px; z-index:-5;padding-top:260px;text-align:right;">
            
            	<div id="erhverv" OnClick="javascript:window.open('index.php?page=erhverv','_self')">Erhverv</div>
                <div id="bolig" OnClick="javascript:window.open('index.php?page=bolig','_self')">Bolig</div>
                <div id="interier" OnClick="javascript:window.open('index.php?page=interior','_self')">{global_content name='cm_interier'}</div>
                <div id="andet" OnClick="javascript:window.open('index.php?page=andet','_self')">Andet</div>
            
            </div>
          
          </div>
But still no show???
gdur
Forum Members
Forum Members
Posts: 142
Joined: Sun Jan 10, 2010 10:59 am

Re: Only show submenu when parent page is active?

Post by gdur »

Yeah but your main menu has not been defined as it was ment to be with CMSMS. If you want to stick to the javascript driven menu you also have to figure your submenu using javascript and that's a whole different approach.
Post Reply

Return to “Modules/Add-Ons”