Results 1 to 3 of 3

Thread: customizing nav_default

  1. #1

    Default customizing nav_default

    Hi there,

    I´m trying to customize the nav_default template. I would like it to render out following HTML:

    <ul class="level_1">[*][*][/list]

    <ul class="level_2">[*][*][/list]

    I have done following:
    Code:
    <ul class="<?php echo $this->level; ?>">
    <?php foreach ($this->items as $item): ?>
    <?php if ($item['isActive']): ?>
    <li class="active<?php if ($item['class']): ?> <?php echo $item['class']; ?><?php endif; ?>"><span class="active<?php if ($item['class']): ?> <?php echo $item['class']; ?><?php endif; ?>"><?php echo $item['link']; ?></span>
    <?php else: ?>
    
    <li<?php if ($item['class']): ?> class="<?php echo $item['class']; ?>"<?php endif; ?>>"<?php if ($item['class']): ?> class="<?php echo $item['class']; ?>"<?php endif; ?><?php if ($item['accesskey'] != ''): ?> accesskey="<?php echo $item['accesskey']; ?>"<?php endif; ?><?php if ($item['tabindex']): ?> tabindex="<?php echo $item['tabindex']; ?>"<?php endif; ?><?php if ($item['nofollow']): ?> rel="nofollow"<?php endif; ?><?php echo $item['target']; ?>><?php echo $item['link']; ?>
    <?php endif; ?>
    <?php endforeach; ?>[/list]
    
    <?php foreach ($this->items as $item): ?>
    <?php echo $item['subitems']; ?>
    <?php endforeach; ?>
    But that renders out a <ul> for each sub items in level_2

    Can anyone help? Thanks!

  2. #2
    Experienced user
    Join Date
    01-12-10.
    Posts
    814

    Default Re: customizing nav_default

    Right now Module::renderNavigation is a recursive function so the template you are editing is always entirely included at the place where you print out the submenu items. If you have three levels this becomes more apparent.

    My first thought on this is that you need to write your own navigation module. But start with a copy from the original. I think the logic needs a little tinkering and it is done...

    Alternatively you can switch at level_2 to do something else within the template. You need to refine the code below and check what happens for third level items...
    Code:
    <?php if ($this->level != 'level_2'): ?>
    <ul class="<?php echo $this->level; ?>">
    <?php foreach ($this->items as $item): ?>
    <?php if ($item['isActive']): ?>
    <li class="active<?php if ($item['class']): ?> <?php echo $item['class']; ?><?php endif; ?>"><span class="active<?php if ($item['class']): ?> <?php echo $item['class']; ?><?php endif; ?>"><?php echo $item['link']; ?></span>
    <?php else: ?>
    
    <li<?php if ($item['class']): ?> class="<?php echo $item['class']; ?>"<?php endif; ?>>"<?php if ($item['class']): ?> class="<?php echo $item['class']; ?>"<?php endif; ?><?php if ($item['accesskey'] != ''): ?> accesskey="<?php echo $item['accesskey']; ?>"<?php endif; ?><?php if ($item['tabindex']): ?> tabindex="<?php echo $item['tabindex']; ?>"<?php endif; ?><?php if ($item['nofollow']): ?> rel="nofollow"<?php endif; ?><?php echo $item['target']; ?>><?php echo $item['link']; ?>
    <?php endif; ?>
    <?php endforeach; ?>[/list]
    <?php else: ?>
    <?php foreach ($this->items as $item): ?>
    <?php if ($item['isActive']): ?>
    <li class="active<?php if ($item['class']): ?> <?php echo $item['class']; ?><?php endif; ?>"><span class="active<?php if ($item['class']): ?> <?php echo $item['class']; ?><?php endif; ?>"><?php echo $item['link']; ?></span>
    <?php else: ?>
    <li<?php if ($item['class']): ?> class="<?php echo $item['class']; ?>"<?php endif; ?>>"<?php if ($item['class']): ?> class="<?php echo $item['class']; ?>"<?php endif; ?><?php if ($item['accesskey'] != ''): ?> accesskey="<?php echo $item['accesskey']; ?>"<?php endif; ?><?php if ($item['tabindex']): ?> tabindex="<?php echo $item['tabindex']; ?>"<?php endif; ?><?php if ($item['nofollow']): ?> rel="nofollow"<?php endif; ?><?php echo $item['target']; ?>><?php echo $item['link']; ?>
    <?php endif; ?>
    <?php endforeach; ?>
    <?php endif; ?>
    
    <?php if ($this->level == 'level_1'): ?>
    <ul class="level_2"><?php endif; ?>
    <?php foreach ($this->items as $item): ?>
    <?php echo $item['subitems']; ?>
    <?php endforeach; ?>
    <?php if ($this->level == 'level_1'): ?>[/list]<?php endif; ?>
    Please excuse my lazy programming in this example. I strongly advice to rewrite before using...

  3. #3

    Default Re: customizing nav_default

    Thanks I´ll give it a try :-)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •