Search code examples
typo3typoscript

TYPO3 hmenu disable one link


I have menu with 2 level. All links are clickable but I want to disable 1 link. This link is being used for opening submenu

         <li class="sub-link"><a href="#">link1</a>
            <ul id="sub-menu">
              <li><a href="#">sublink</a></li>
              <li><a href="#">sublink2</a></li>
            </ul> <!-- sub-menu -->
          </li>
          <li><a href="#">link2</a></li>
          <li><a href="#">link3</a></li>
          <li><a href="#">link4</a></li>
          <li><a href="#">link5</a></li>

I want to disable link 1. I have such typoscript:

lib.menu.main  = HMENU
lib.menu.main {
    special = list
    special.value =  22,154,88
    alwaysActivePIDlist = 22
    1 = TMENU
    1.NO = 1          
    1.wrap = <ul>|</ul>
    1.NO.wrapItemAndSub = <li>|</li>
    1.IFSUB=1
    1.IFSUB.wrapItemAndSub = <li class="sub-link">|</li>
    2 < .1
    2.wrap = <ul id="sub-menu">|</ul>
    2.NO.wrapItemAndSub = <li>|</li>
}

How I can decide this problem?


Solution

  • So i got two possibilities for you to solve this problem:

    The first one is to read the Typo3-Documentation and look up for "optionSplit" and "doNotLinkIt"-options. They should help you solving your problem within typoscript.

    The other is to solve it using Javascript/JQuery. You could select the (in your example above) FIRST item of the menu and replace the link with whatever you want.

    $(document).ready(function(){
        $('.menu a').first().attr('href', '#');
    });
    

    I made you a fiddle with the whole example: https://jsfiddle.net/bdrsssv7/


    Make sure you do not insert the Javascript in the HTML template because it will not be available on pages with other html-templates then. Just do a js-file and insert it via typoscript like this:

    page.includeJS.file1 = fileadmin/yourTemplateLocation/yourFile.js
    

    I hope one of the two solutions i mentioned could help you