Page 1 of 1

Child Pages in Sidebar

Posted: Fri Jun 20, 2014 10:39 am
by singhabhishek251
I have this below code as User Defined Tag {sidemenu}
It is working fine on a previous website, but when I copied same in new install, then it is not accepting this UDT {sidemenu} after force submitting the pages are getting deformed.
can you help me get the error from here or other code to call child pages in sidebar. I am not good with Menu Manager, so any UDT or other solution than Menu Manager will help.

Code: Select all

global $gCms;
$manager =& $gCms->GetHierarchyManager();
$thisPage = $gCms->variables['page_name'];
$currentNode = &$manager->sureGetNodeByAlias($thisPage);

$nodes = $currentNode->getChildren();

if ($currentNode->hasChildren()) {
  echo '<h2 class="leftTitle">In this section:</h2><ul>';
  foreach ($nodes as $node) {
     $content= $node->getContent();
     $url = $content->GetURL();
    if ($url == "#") { /* section header has no link by default */
      $url = "index.php?page=".$content->Alias();
    }
    echo "<li><a href=\"".$url."\">".$content->MenuText()."</a> </li>";

  }
  echo "</ul>";

}
else if($currentNode->hasChildren()==false)
{
  $nodes = &$currentNode->getParentNode()->getChildren();
    echo '<h2 class="leftTitle">In this section:</h2><ul>';
  foreach ($nodes as $node) {
     $content= $node->getContent();
     $url = $content->GetURL();
    if ($url == "#") { /* section header has no link by default */
      $url = "index.php?page=".$content->Alias();
    }
    echo "<li><a href=\"".$url."\">".$content->MenuText()."</a> </li>";

  }
  echo "</ul>";
}

Re: Child Pages in Sidebar

Posted: Fri Jun 20, 2014 11:45 am
by velden
Change

Code: Select all

global $gCms;
to

Code: Select all

$gCms = cmsms();
And learn Menu Manager. Really.

Re: Child Pages in Sidebar

Posted: Fri Jun 20, 2014 11:56 am
by Rolf

Code: Select all

{menu childrenof=$page_alias}

Re: Child Pages in Sidebar

Posted: Fri Jun 20, 2014 12:21 pm
by singhabhishek251
velden wrote:Change

Code: Select all

global $gCms;
to

Code: Select all

$gCms = cmsms();
And learn Menu Manager. Really.
I changed, but still it is not applying when I am writing {sidemenu} in template after saving the UDT, then it is not applying I mean to getting saved and after removing it is applying fine. There is no output.

I have used class in template as below, after removing this also nothing.
</__body id="{$page_alias}">

Re: Child Pages in Sidebar

Posted: Fri Jun 20, 2014 12:24 pm
by velden
I'm sorry, I don't know why it doesn't work. Did not check the whole code.

Will not look into this further. Better invest your time learning Menu Manager. That has all those thing built in already.

Re: Child Pages in Sidebar

Posted: Fri Jun 20, 2014 12:26 pm
by singhabhishek251
Rolf wrote:

Code: Select all

{menu childrenof=$page_alias}
I tried this also but there is no output.

Re: Child Pages in Sidebar

Posted: Fri Jun 20, 2014 12:30 pm
by singhabhishek251
Thanks for all your help "velden", I understand that you may not give much time into individual issues.

Thanks for all you help, I found something with menu manager and it is working fine I hope. As I am able to see the output and now I will investigate how to customize the design of this output to make it look better.

Code: Select all

{menu template='simple_navigation.tpl' start_level='2' collapse='1'}
I hope others also can use this code.

Re: Child Pages in Sidebar

Posted: Fri Jun 20, 2014 12:56 pm
by velden
It's not about individual problems. It's about building your own Menu Manager in stead of using the excellent built-in version.

Have a look at the sample templates and read the modules help.

Note that you can 'Import' an sample template into the database (icon behind the templates). Give it a name and make it default (or use 'template=' parameter in {menu} call).

You can customize that template to suit your needs.

Re: Child Pages in Sidebar

Posted: Fri Jun 20, 2014 2:09 pm
by singhabhishek251
Thanks for the guideline velden, with individual issue I mean to say that you have to support a big community and help many others like me and giving much time for a small issue is definitely time consuming.

I will definitely play around with menu manager to learn now, only I was little concern about time for this because of lack of time as it was difficult to learn completely new thing in between some important work.