HOME   SITEMAP   CONTACT   NEWS   BLOG
Search


Framework HTML Navigation


Only 3 steps are needed to have your fully customized dynamic navigation or sitemap:
  1. give the navigation data (links)
  2. specify the styles
  3. specify the current page the user is looking at

Uses styles, they may come from PHP arrays or XML files.

The navigation of blueshoes.org as well as the sitemap is made using this class. Based on browser sniffing there exist two different style files for the navigation; one for javascript-aware browsers, one for the others.

Features:

  • Every level of the navigation can have it's own style definitions.
  • The placeholders __LINK__, __URL__, __TARGET__, __CAPTION__ and __CAPTION_URLENCODE__ can be used.
  • Navigation elements can look different based on the currently active page. The current active page can be 'self', 'sibling', 'parent' or 'child' of the element.
  • PHP code can be used in link definition styles for maximum flexibility that gets executed on run-time.

Very basic example:

At first we define the navigation data:

<?php
$navData 
= array(
  array(
    
'caption'  => 'Home',
    
'url'      => '/',
  ), 
  array(
    
'caption'  => 'HTML',
    
'url'      => '/en/framework/html/',
    
'children' => array(
      array(
        
'caption' => 'Form Package',
        
'url'     => '/en/framework/html/form/',
      ),
      array(
        
'caption' => 'Table Triology',
        
'url'     => '/en/framework/html/table/',
      ),
      array(
        
'caption' => 'Navigation Class',
        
'url'     => '/en/framework/html/navigation/',
      ),
    ),
  ), 
);
?>

Then we define the style data:

<?php
$navStyle 
= array(
  
'head'     => '<table>'
  
'foot'     => '</table>'
  
'empty'    => 'no navigation data'
  
'level'      => array(
    
'1+'         => array(
      
'head'       => ''
      
'foot'       => '<tr><td colspan="100%">&nbsp;</td></tr>'
      
'link'       => array(
        
'default'           => '<tr><td><?php for ($i=1; $i<$level; $i++) { echo "&nbsp;&nbsp;&nbsp;&nbsp;"; }?>__LINK__</td></tr>'
        
'defaultActiveSelf' => '<tr><td><?php for ($i=1; $i<$level; $i++) { echo "&nbsp;&nbsp;&nbsp;&nbsp;"; }?><b>__LINK__</b></td></tr>'
      )
    )
  )
);
?>

Then we put it all together:

<?php
$n 
=& new Bs_HtmlNavigation();
$n->setStyle($navStyle);
$n->setData($navData);
$n->setCurrentPage($bsEnv['requestPath']); //that is '/en/framework/html/navigation/'
echo ($n->toHtml());
?>

And this is the result:

Home
HTML
    Form Package
    Table Triology
    Navigation Class