ParentPage droplet modified to show top level if no parent

lausianne

Hi Karsten,

Thank you, I'm glad you find it useful.

Search: I have actually never used a Search field on a WB site ... so I wasn't aware of the problem.
But then, no top level page has a parent. I solved this in index.php, not ParentPage:

           <div id="sidemenu">
               <?php
                    $mb2 
show_menu2(0,SM2_ROOT+1,SM2_ALL,SM2_TRIM|SM2_BUFFER);
                    if (
$mb2!='') echo '<div id="parent">[[ParentPage]]</div>'.$mb2;
                
?>
   
           </div>


This works where I applied it, because the side menu has a blank background and it does not disturb the design, when the side menu disappears completely. I don't know if that would work in your design.
You could still add other code to display the top level item in the side menu:

<?php
   
if ($mb2!='') echo '<div id="parent">[[ParentPage]]</div>'.$mb2;
   else echo 
'<div id="parent">Search</div>'; (or some code to get the current top level item)
?>


Just an idea.

Cheers,
Ralf.

ichmusshierweg

Hi Ralf,

you are my hero of the day! That was exactly what I was looking for Thanks a lot.

I did some minor modifications to avoid theese formatting issues. May it is helpful for anybody.
$info = show_menu2(0, SM2_CURR, SM2_START, SM2_ALL|SM2_BUFFER, '[if(class==menu-current){[level] [sib] [sibCount] [parent]}]', '', '', '');
list($nLevel, $nSib, $nSibCount, $nParent) = explode(' ', $info);

// show up level
if ($nLevel > 0) {
$lev = $nLevel - 1;
return show_menu2(0, SM2_ROOT, SM2_CURR, SM2_CRUMB|SM2_BUFFER, "[if(level==$lev){[a][menu_title]</a>}]", '', '', '');
}
else {
return show_menu2(0, SM2_ROOT, SM2_CURR, SM2_CRUMB|SM2_BUFFER, "[if(level==0){[a][menu_title]</a>}]", '', '', '');
}


That works fine but there is still one probleme left: Using the search-form.
If I to this, an error appiers: "Error in: ParentPage, no correct returnvalue." (Please take a look to the attached picture)
This mkes sense, because the search doesen't have no parent and the search is not part of show_menu2. Is there a way just to return a single word with som emodification in the "ParentPage-Code" above.

Thanks a lot guys, and regards from bavaria
Karsten



[gelöscht durch Administrator]

Argos

Quote from: lausianne on November 09, 2009, 03:19:24 PM
Hi Argos,

right, a link to itself. The reason is simple: I use this for a side menu. The top level (e.g. "Home") is on the top of the menu. I want the menu to stay complete, whereever I am.
You don't remove items from any other menu, when you are on the page to which that item links, do you ...

The side menu disappears completely when there are no sub-pages. Somehow I found it simpler to use ParentPage than sm2 directly, don't remember exactly why.


Hi Ralf,

I understand what you want now. I was looking through the droplets, and I think http://www.websitebakers.com/pages/droplets/official-library/navigation/sitemapchild.php will do the same. Or is it still different? Well, if your solution works fine, than it's okay to use that of course.
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

lausianne

Hi Argos,

right, a link to itself. The reason is simple: I use this for a side menu. The top level (e.g. "Home") is on the top of the menu. I want the menu to stay complete, whereever I am.
You don't remove items from any other menu, when you are on the page to which that item links, do you ...

The side menu disappears completely when there are no sub-pages. Somehow I found it simpler to use ParentPage than sm2 directly, don't remember exactly why.

Cheers, Ralf.

Argos

Hi Ralf,

just curious: why would you want to show a link to the current page? Because that is what your code shows if there is no parent: a link to itself...
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

lausianne


Hi Argos,

in his tip he says this:
QuoteIf you don't want to show anything if there is no parent page, replace the last line in return ' ';  (Return a single whitespace)

I don't show "nothing", but always at least the top level. And I added [ul/li]-tags to get the formatting right.

Cheers, Ralf.

Argos

Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

lausianne

Hi,

I have grown really fond of droplets. A great advantage is that they can easily be modified without need to get into module programming.

I used the ParentPage droplet for a side menu. What was not nice in my case was that the droplet showed nothing (or "(no parent)") when on the top level. So I modified it slightly. What now works well for me is this:

$info = show_menu2(0, SM2_CURR, SM2_START, SM2_ALL|SM2_BUFFER, '[if(class==menu-current){[level] [sib] [sibCount] [parent]}]', '', '', '');
list($nLevel, $nSib, $nSibCount, $nParent) = explode(' ', $info);

// show up level
if ($nLevel > 0) {
$lev = $nLevel - 1;
return show_menu2(0, SM2_ROOT, SM2_CURR, SM2_CRUMB|SM2_BUFFER, "[if(level==$lev){[ul][li][a][menu_title]</a></li></ul>}]", '', '', '');
}
else {
return show_menu2(0, SM2_ROOT, SM2_CURR, SM2_CRUMB|SM2_BUFFER);
}


The [ul/li] bit in the first return line was necessary to get the formatting right.

I wonder if such minor modifications are at all interesting to anyone, since it is kind of trivial for most people in this forum, I believe. Maybe someone can enlighten me what the level of sophistication is that a modification should meet to be worth posting.

Cheers,
Ralf.