• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Spain CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Show children of current page unless hidden from the menu
PostPosted: Fri Aug 10, 2012 2:28 am 
Offline
Forum Members
Forum Members

Joined: Mon Mar 14, 2011 1:16 am
Posts: 183
Location: Brisbane, Australia
I'm using a UDT for CMS 1.11 called list_children to display the children of the page currently being viewed. If there is at least one child page, I wrap a HTML <section> element around the list. That all works fine.

Now for the tricky bit. I only want to list pages that are set to appear in the menu. Again, I can achieve this, but the problem is that the outer HTML elements (<ul> and <section>) will be displayed regardless.

So, what needs to happen is this logical process:

1. Are there child pages of the current page? If yes, continue.
2. Is there at least one page that is set to show in the menu? If yes, continue.
3. Is this showing in the sidebar (using the parameter when calling the UTD)? If yes, wrap the whole block in <section>.
4. Wrap the list items in the <ul> element.
5. Loop through the child pages, ignoring those that that NOT set to show in the menu. Output each to an <li>.
6. Close the </ul> and </section>.

Here's what I have so far. This is completely functional except that it shows the outer HTML elements regardless.

Code:
global $gCms;

// invoke menu manager
$manager =& $gCms->GetHierarchyManager();

// get the current page name
$thisPage = $gCms->variables['page_name'];

// define a specific page alias or use the current page
if (isset($params['the_page_alias'])) {
   $currentNode = &$manager->sureGetNodeByAlias($params['the_page_alias']);
}
else {
   $currentNode = &$manager->sureGetNodeByAlias($thisPage);
}

// get the list of child pages
$nodes = $currentNode->getChildren();

// if there are children...
if ( $currentNode->hasChildren() ) {

   // is this showing in the sidebar?
   if (isset($params['sidebar'])) {
      if ($params['sidebar'] == 'yes') {
         echo '<section id="subpages">';
         $sidebar_end = '</section>';
      }
   }

   // redefine or hide the default list title
   if (isset($params['title'])) {
      if ($params['title'] !== '') {
         echo '<h3>'.$params['title'].'</h3>';
      }
      else { /* do nothing */ }
   }
   else {
      echo '<h3>Pages in this section:</h3>';
   }

   // set a class name for the list
   if (isset($params['class'])) {
      if ($params['class'] !== '') {
         echo '<ul class="'.$params['class'].'">';
      }
      else { /* do nothing */ }
   }
   else {
      echo '<ul>';
   }

   // show each item in a list format
   foreach ($nodes as $node) {
   
      $content= $node->getContent();
      
      $url = $content->GetURL();
      
      // hide section header pages
      if ($url == "#") {
         $url = "index.php?page=".$content->Alias();
      }
      echo "<li><a href=\"".$url."\">".$content->MenuText()."</a> </li>";

   }

   echo "</ul>";

// if it's in the sidebar, close the element
echo $sidebar_end;

}


Top
 Profile  
 
 Post subject: Re: Show children of current page unless hidden from the men
PostPosted: Fri Aug 10, 2012 10:27 am 
Offline
Power Poster
Power Poster
User avatar

Joined: Wed Sep 05, 2007 8:03 pm
Posts: 3643
Location: The Netherlands
you might want to check the available parameters of the menu tag in the module help of menumanager.
My guess is that you don't need a udt at all

_________________
Get nice guestbook messages from your site visitors with the brand new Gbook module.
Integrate Piwik Web Analytics in your site admin with the Piwik module.
Extend your global site settings with the Custom Global Settings module.
The Fourth Dutch CMS Made Simple Workshop on April 9 2011 was great fun! Read all about it here
Announcement: The Fifth Dutch CMS Made Simple Workshop coming up?


Top
 Profile  
 
 Post subject: Re: Show children of current page unless hidden from the men
PostPosted: Fri Aug 10, 2012 10:49 am 
Offline
Forum Members
Forum Members

Joined: Mon Mar 14, 2011 1:16 am
Posts: 183
Location: Brisbane, Australia
You may be right, but I'm using this UDT in a few different places so I need to specify its title, CSS class, location and other factors (truncated from this code). I'm not sure how I could achieve all of this with menu manager.


Top
 Profile  
 
 Post subject: Re: Show children of current page unless hidden from the men
PostPosted: Fri Aug 10, 2012 11:53 am 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Tue Aug 12, 2008 9:30 pm
Posts: 1979
Location: Feldkirchen in Kärnten, Austria
Like Jos said i don't see a reason fo a UDT either, for you sidebar section or classes all you need is additional content block which is proccessed before {menu}

so somewhere on top of template you would do:

Code:
{content block='is_sidebar' assign='is_sidebar' label='Enable Sidebar' size='20' oneline='true'}
{content block='i_want_class' assign='i_want_class' label='Enter Class name' oneline='true'}
{content block='from_alias' assign='from_alias' label='Specify page alias for menu to show' oneline='true'}


then in menu
Code:
{if !empty($is_sidebar)}
  <section id="subpages">
{/if}
and so and on the rest of template
{if !empty($is_sidebar)}
  </section>
{/if}


and in page template where menu is called
Code:
{if !empty($from_alias)}
  {menu childrenof=$from_alias .. and other params}
{else}
  {menu start_level='2' .. or whatever should happen by default}
{/if}


At least from what i understand you want to achieve, but anyway all you need is proper logic to come to your goal.

_________________
CMSMS Blog - I do this!
Forge profile
Github profile
Twitter
=============================================
Support CMSMS


Top
 Profile  
 
 Post subject: Re: Show children of current page unless hidden from the men
PostPosted: Fri Aug 10, 2012 12:02 pm 
Offline
Forum Members
Forum Members

Joined: Mon Mar 14, 2011 1:16 am
Posts: 183
Location: Brisbane, Australia
Thanks mate for the reply. That's not quite what I'm after, though. Looking at your code, the sidebar section is going to be shown even if there are no menu items to display.

I also don't want to edit it per-page. I just want to drop this into the sidebar of the page template and have it automatically use the current page alias, so I don't need any of those content block settings.

And lastly, even if I moved <section> to within the menu template, how would I be able to specify a class for that element for each new instance of the menu?


Top
 Profile  
 
 Post subject: Re: Show children of current page unless hidden from the men
PostPosted: Fri Aug 10, 2012 12:39 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Tue Aug 12, 2008 9:30 pm
Posts: 1979
Location: Feldkirchen in Kärnten, Austria
Without actually knowing what you are after cause it all doesn't make sense to me :) but trying to answer hopefully correct.

If my guess is correct you want to show sidebar menu if page has children and on all children pages of that page.
This can be easily solved with CGSimpleSmarty.
Usually i do all of the logic on top of tmeplate so you would do:

Code:
{* get parent alias from current page *}
{$cgsimple->get_parent_alias($page_alias, 'has_parent')}
{*do the logic *}
{capture assign='is_parent'}{if !empty($has_parent)}{$has_parent}{else}{$page_alias}{/capture}
{$cgsimple->get_page_title($is_parent, 'has_title')}


Then in MenuManager template

Code:
<section class='{$is_parent}'>
<h3>{$has_title}</h3>

the menu stuff

</section>


Then where you call your sidebar menu
Code:
{menu childrenof=$is_parent}


Bus basically to hide inactive or hidden pages in you udt add following where you have:

Code:
// show each item in a list format
   foreach ($nodes as $node) {
   
      $content= $node->getContent();
      // add this here
      if(!$content->Active() || !$content->ShowInMenu()) continue;

_________________
CMSMS Blog - I do this!
Forge profile
Github profile
Twitter
=============================================
Support CMSMS


Top
 Profile  
 
 Post subject: Re: Show children of current page unless hidden from the men
PostPosted: Fri Aug 10, 2012 2:26 pm 
Offline
Forum Members
Forum Members

Joined: Mon Mar 14, 2011 1:16 am
Posts: 183
Location: Brisbane, Australia
I think that might work, but I'll have to try it tomorrow. For clarity, here's what I'm trying to do:

* Have a single function/call (e.g. a UDT) which allows me to show a list of all child pages of either the current page, or a specific page alias.

* I want the function to be flexible so that I can use it in multiple websites. Sometimes it will appear in the sidebar (which is why I'm trying to assign a class to the UL), but other times it might appear in the general page content area or somewhere else.

* I don't want to have to manually exclude any page aliases (which is great in your solution -- I'm just clarifying that).

* The whole reason I need this is because I sometimes have a 'Thank you' page which is only used as a confirmation page after a Form Builder form is submitted. I want the client to be able to edit this page and I don't want to involve any GCBs or anything else, so that needs to be a normal page. Obviously I don't show it in the menu and I also don't want it to appear in the sidebar. There may be other such pages so I'm just filtering out all pages that aren't set to show in the menu, to avoid that issue.

* For this particular website, I want to show the block in the sidebar, so I need to firstly assign the class "sidebar" to the UL, but I also need to skip the hidden pages (as per the point above).

As I said, I'll have to test out your code but this is the conceptual logic:

1. If the current page has children and there's at least one page that is set to show in the menu, list all of those pages. If not, stop here.
2. Allow me to assign a Class or ID to the <section> that wraps around the <UL>.

That's pretty much it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
A2 Hosting