Results 1 to 7 of 7

Thread: Highlight Parent of selected item in dropdown menu

  1. #1
    New user
    Join Date
    07-01-10.
    Location
    Midlands, UK
    Posts
    26

    Default Highlight Parent of selected item in dropdown menu

    Hi

    I am developing my first site using Contao and have a question regarding multi-level navigation.

    The menu I have is working perfectly and renders the following html:

    Code:
    <ul id="mainDropDown" class="level_1">[*]<a class="first" blah...>wibble</a>[*]<a class="submenu" blah...>wibble
    <ul class="level_2">[*]<a class="first" blah...>wibble</a>[*]<a blah...>wibble</a>[*]<a class="last" blah...>wibble</a>[/list][/list]
    My 'nav_default_mod.tpl' is set to:

    Code:
    <ul <?php if ($this->level=="level_1"): ?>id="mainDropDown"<?php endif; ?> 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 echo $item['subitems']; ?>
    <?php else: ?>
    <li<?php if ($item['class']): ?> class="<?php if ($this->level=="level_1"): ?><?php echo 'trigger'; ?><?php endif; ?>
    <?php if ($this->level=="level_2"): ?><?php echo $item['class']; ?><?php endif; ?>"
    <?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 echo $item['subitems']; ?>
    <?php endif; ?>
    <?php endforeach; ?>[/list]

    And the 'active' class gets set when choosing a child element from the '[*]<a class="submenu" blah...>wibble' parent.

    What I would like to do is also add the 'active' class to the '[*]<a class="submenu" blah...>wibble' parent as well as the child so I can see from the level_1 which which menu contains the currently selected child.

    I hope that makes sense.

    Also, if in reading this you can answer another related question:

    How can I create a parent item that doesn't have a page associates with it so that it simply forms an unlinked main menu entry?

    Thanks for your time

  2. #2
    User Toflar's Avatar
    Join Date
    06-19-09.
    Location
    Lyss, Switzerland
    Posts
    170

    Default Re: Highlight Parent of selected item in dropdown menu

    Hi redwax

    1) You don't need to change anything in the template at all. The current navigation link gets the class "active" and all its parents get "trail" Use Firebug!

    2) Just add a page and forward it to another content. Or what would you like to do with an unlinked navigation entry?
    Regards

    Yanick - Contao core developer @terminal42 gmbh

  3. #3
    New user
    Join Date
    07-01-10.
    Location
    Midlands, UK
    Posts
    26

    Default Re: Highlight Parent of selected item in dropdown menu

    1) You don't need to change anything in the template at all. The current navigation link gets the class "active" and all its parents get "trail" Use Firebug! ?
    I feel like an idiot - I do use firebug but some how I completely missed that. Thank you.

    2) Just add a page and forward it to another content. Or what would you like to do with an unlinked navigation entry?
    Simply, for level_1 menu entries that have a dropdown with level_2 child menu entries, I would like the level_1 to simply be a menu header, not a link to a page in itselft, so it becomes unclickable. Does this make sense? I'm not sure I have described myself overly well.

    Thanks again for your time in assisting me.

  4. #4
    User Toflar's Avatar
    Join Date
    06-19-09.
    Location
    Lyss, Switzerland
    Posts
    170

    Default Re: Highlight Parent of selected item in dropdown menu

    Hmm, yes it does but I can't come up with a solution for you right now.
    Maybe there is someone else who can help you out
    Regards

    Yanick - Contao core developer @terminal42 gmbh

  5. #5
    Experienced user
    Join Date
    06-10-09.
    Location
    Atlanta, Georgia
    Posts
    611

    Default Re: Highlight Parent of selected item in dropdown menu

    redwax,

    I just tried this and it seems to work. From the default nav_default.tpl, you just need to add an "or" statement in line 3, so it will read "if the nav item is active or has child menus, then don't link it and wrap in a span".

    Just replace line 3 with this:
    Code:
    <?php if (($item['isActive']) || ($item['subitems'])): ?>
    The full template will then look like this:
    Code:
    <ul class="<?php echo $this->level; ?>">
    <?php foreach ($this->items as $item): ?>
    <?php if (($item['isActive']) || ($item['subitems'])): ?>
    <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 echo $item['subitems']; ?>
    <?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 echo $item['subitems']; ?>
    <?php endif; ?>
    <?php endforeach; ?>[/list]

  6. #6
    Experienced user
    Join Date
    06-10-09.
    Location
    Cape Town, South Africa
    Posts
    1,387

    Default Re: Highlight Parent of selected item in dropdown menu

    Take a look at www.contao-factory.com. We auto expand the menu trail and accordion the rest with a mouse over.

  7. #7
    New user
    Join Date
    07-01-10.
    Location
    Midlands, UK
    Posts
    26

    Default Re: Highlight Parent of selected item in dropdown menu

    Quote Originally Posted by thyon
    Take a look at http://www.contao-factory.com. We auto expand the menu trail and accordion the rest with a mouse over.
    Unfortunately, this doesn't show anything at the moment. What I am left with tryiong to do is create a parent item that doesn't have a page associates with it so that it simply forms an unlinked main menu entry with child entries that are links?

    Is there a reference somewhere of all the variables available. For instance, in the unrelated code...

    Code:
    if (($item['isActive']) || ($item['subitems'])
    ...there is mention of 'isActive' and 'subitems'. Is there a list somewhere of all the available $item['blah'] etc. I'm sure I had seen something once upon a time.

    Thank you.

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
  •