Results 1 to 7 of 7

Thread: Dropdown menu where first level dont link to page ?

  1. #1
    User
    Join Date
    04-01-10.
    Posts
    292

    Dropdown menu where first level dont link to page ?

    Hello,
    I have this structure :

    • Page A
      • Page A1
      • Page A2
      • ...

    • Page B
      • Page B1
      • Page B2
      • ...



    My problem : A and B shouldn't redirect to pages. They must only be "buttons" to drop down A1, A2... or B1, B2...

    How can i do it with Contao ?

    Thanks for help.
    Last edited by charled; 08/28/2020 at 01:55. Reason: [solved]

  2. #2
    User Andreas's Avatar
    Join Date
    07-11-09.
    Location
    Mönchengladbach
    Posts
    499

    Default

    1. By customizing your nav_ template.

    2. By handling (removing) the click events on first level <a>s with JavaScript. If you use JS for your menu anyway, you simply can remove the default click event with JS and thus don't need a custom template which you have to review in future updates.

    edit: Maybe this way
    PHP Code:
    <script>
    (function($) {
      $(
    document).ready(function() {

        var 
    firstLevelLinks = $('.mainnav > ul > li > a');

        
    // do this on first level click
        
    firstLevelLinks.on('click', function(ev) {
          
    ev.preventDefault();
          
    // do other stuff
        
    });

      });
    })(
    jQuery);
    </script> 
    Last edited by Andreas; 08/14/2020 at 15:03.
    Web-Development, Freelancer, Burgtech, XHTML, HTML5, CSS, PHP, Javascript, MooTools, MySQL and more
    Amazon wishlist

  3. #3
    User
    Join Date
    04-01-10.
    Posts
    292

    Default

    Quote Originally Posted by Andreas View Post
    1. By customizing your nav_ template.
    Thnaks Andreas. I would like a css only solution. Which way do I customize my nav_template ?

  4. #4
    User Andreas's Avatar
    Join Date
    07-11-09.
    Location
    Mönchengladbach
    Posts
    499

    Default

    1. In BE create a copy of template nav_default.
    2. Rename it to nav_no-first-level-links. (nav_ is mandatory, the rest is free)
    3. In your FE module type navigation choose this template.
    4. Edit this template.

    Change this line
    PHP Code:
        // old
        <?php if ($item['isActive']): ?>
        // new
        <?php if ($item['isActive'] || $this->level == 'level_1'): ?>
    Last edited by Andreas; 08/18/2020 at 22:17.
    Web-Development, Freelancer, Burgtech, XHTML, HTML5, CSS, PHP, Javascript, MooTools, MySQL and more
    Amazon wishlist

  5. #5
    User
    Join Date
    04-01-10.
    Posts
    292

    Default

    ok. But it déactivates all level_1 menu. in fact, I need to deactivate only those who have submenus (subitems).

  6. #6
    User
    Join Date
    04-01-10.
    Posts
    292

    Idee

    The solution is to use contao-folder-page extension (and apply nav_folder template to the menu module).

  7. #7
    User Andreas's Avatar
    Join Date
    07-11-09.
    Location
    Mönchengladbach
    Posts
    499

    Default

    It is better not to depend on extensions.

    New template solution:
    PHP Code:
        // old
        <?php if ($item['isActive']): ?>
        // new
        <?php if ($item['isActive'] || ($this->level == 'level_1' && $item['subitems'])): ?>
    Web-Development, Freelancer, Burgtech, XHTML, HTML5, CSS, PHP, Javascript, MooTools, MySQL and more
    Amazon wishlist

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
  •