Page 1 of 1

UDT to display list of active sub pages [Solved]

Posted: Thu Oct 13, 2011 1:15 am
by deschnell
So I'm almost there, thanks to this UDT code - http://wiki.cmsmadesimple.org/index.php ... rrent_page

Code: Select all

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

$nodes = $currentNode->getChildren();

if ($currentNode->hasChildren()) {
  echo '<ul class="customlist">';
  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>";
}
But - it displays inactive pages as well, which isn't what I want. I need it to filter out the inactive pages, but not too sure which calls I need to make - I'm a newbie^2 when it comes to this kind of smarty stuff. There are a couple examples on that same page linked above working with active pages, but not too sure how to incorporate into the above code.

Re: UDT to display list of active sub pages

Posted: Thu Oct 13, 2011 11:37 am
by Jos
Is there a reason that you can not simply use the menu tag for this?

Code: Select all

{menu childrenof=$page_alias}
MenuManager help says:
(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: UDT to display list of active sub pages [solved]

Posted: Thu Oct 13, 2011 2:59 pm
by deschnell
never thought about it, and does work. I assumed at first I needed to replace "page_alias" with the page name/alias/ID - but that doesn't work. the variable needs to read #page_alias. Thanks!!