Jump to content


Menubuilder With Weblink Target Support


  • You cannot reply to this topic
No replies to this topic

#1 breezer

    Likes Etomite Forums!

  • Member
  • PipPip
  • 308 posts

Posted 06 January 2006 - 01:48 AM

I have been working on solving the issue of opening weblinks in a new window and here is the solution. Although at the moment I have only modified the stock MenuBuilder (and also the horiz menu that comes with the andreas09 template), menu snippet authors can integrate the code into their snippets fairly easily I'm sure...

What I did:
1. added content, longtitle to the $fields variable

2. added a check to see if the type is "reference" (weblink) or regular document

3. in the document edit area in the manager, when editing or creating a weblink, the longtitle is used for the target attribute in the link - if you leave the longtitle blank it willl default and stay in the current window.

longtitle example: target='_blank'

/*  
 MenuBuilder
     1/05/06
     support for weblinks opening in a new window

  added:  content, longtitle to the $fields variable
          now in the document area of the manager, when you create a weblink
          the longtitle setting is where you need to add the target

         example:  target='_blank'

         I also removed the [~ ~] from the weblink part of the link code

*/
$id = isset($id) ? $id : $etomite->documentIdentifier;
$sortby = "menuindex";
$sortdir = "ASC";
$fields = "id, type, pagetitle, description, parent, alias, content, longtitle";

$indentString="";

if(!isset($indent)) {
    $indent = "";
    $indentString .= "";
} else {
    for($in=0; $in<$indent; $in++) {
        $indentString .= "&nbsp;";
    }
    $indentString .= "&raquo;&nbsp;";
}

$children = $etomite->getActiveChildren($id, $sortby, $sortdir, $fields);
$menu = "";
$childrenCount = count($children);
$active="";

if($children==false) {
    return false;
}
for($x=0; $x<$childrenCount; $x++) {
        if($children[$x]['id']==$etomite->documentIdentifier) {
                $active="class='highLight'";
        } else {
                $active="";
        }

// This is the area which checks to see if the
// document is a type "reference" (weblink) then
// checks whether the document longtitle setting is empty
// (that is where you add your target)
if($children[$x]['type'] == 'reference')  {
         if($children[$x]['longtitle'] !=''){
           $target = $children[$x]['longtitle'];
           }else{
           $target ="";
           }
     if($children[$x]['id']==$etomite->documentIdentifier || $children[$x]['id']==$etomite->documentObject['parent']) {
                $menu .= "<a ".$active." href='".$children[$x]['content']."' ".$target.">$indentString".$children[$x]['pagetitle']."</a><br>[[MenuBuilder?id=".$children[$x]['id']."&indent=2]]";
        } else {
                $menu .= "<a href='".$children[$x]['content']."' ".$target.">$indentString".$children[$x]['pagetitle']."</a><br>";
        }
 }else{

// this is a regular internal link
        if($children[$x]['id']==$etomite->documentIdentifier || $children[$x]['id']==$etomite->documentObject['parent']) {
                $menu .= "<a ".$active." href='[~".$children[$x]['id']."~]'>$indentString".$children[$x]['pagetitle']."</a><br>[[MenuBuilder?id=".$children[$x]['id']."&indent=2]]";
        } else {
                $menu .= "<a href='[~".$children[$x]['id']."~]'>$indentString".$children[$x]['pagetitle']."</a><br>";
        }
 } // end else

}
return $menu."";


hopefully some of the other snippet authors can use this code and make their snippets weblinkable too... :betterwink:

Edited by breezer, 07 January 2006 - 06:56 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users