TYPO3 hmenu disable one link - typo3

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">link1
<ul id="sub-menu">
<li>sublink</li>
<li>sublink2</li>
</ul> <!-- sub-menu -->
</li>
<li>link2</li>
<li>link3</li>
<li>link4</li>
<li>link5</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?

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

Excluding a specific PID (18) from the menu in Typoscript:
lib.menu = HMENU
lib.menu {
special = rootline
special.range = 2,0
1 = TMENU
1 {
NO {
allWrap = <li> | </li>
doNotLinkIt.override = 1
doNotLinkIt.override.if {
value = 18
equals.field = uid
}
}
}
}
OR exclude multiple specific PIDs (18,19,20) from the menu
lib.menu.1.NO.doNotLinkIt.override.if {
value = 18,19,20
isInList.field = uid
}

Related

Typoscript HMENU: get level 1 title in level 2 navigation

I need to create a menu where, for mobile purposes, before all entries of level 2 there is the title of level 1. Example: my structure looks like this:
team
Max
Sepp
projects
project 1
project 2
now I want my navigation to look like this:
<ul>
<li>
<a>Team</a>
<div class="dropdown-menu">
<ul>
<li>Team</li>
<li><a>Max</a></li>
<li><a>Sepp</a></li>
</ul>
</div>
</li>
<li>
<a>Projects</a>
<div class="dropdown-menu">
<ul>
<li>Projects</li>
<li><a>Project 1</a></li>
<li><a>Project 2</a></li>
</ul>
</div>
</li>
</ul>
So I need in level 2 the title of level 1. how to I access field: nav_title for the parent element?
My typoscript looks like this:
temp.nav = HMENU
temp.nav {
1 = TMENU
1 {
expAll = 1
wrap = |
noBlur = 1
stdWrap.innerWrap.cObject = LOAD_REGISTER
stdWrap.innerWrap.cObject {
level1Title.field = nav_title//title
}
NO = 1
NO {
...
}
}
2 = TMENU
2 {
expAll = 1
stdWrap.dataWrap = <ul><li> {register:level1Title}</li>|</ul><a>Jetzt Mitglied werden</a></div>
noBlur = 1
NO = 1
NO {
...
}
}
}
I tried it with LOAD_REGISTER but that doesnt work. Any suggestions?
what you want is the default behaviour of TYPO3 menus. You just need to set the correct wrapping. Do the wrapping where it belongs:
temp.menu = HMENU
temp.menu {
1 = TMENU
1 {
expAll = 1
wrap = <ul>|</ul>
NO = 1
NO {
wrapItemAndSub = <li>|</li>
}
}
// as you have no specific wrapping all levels can be generated the same:
2 < .1
3 < .2
}
if you want specific wraps on each level you can adapt it after copying (in this example you can see where a wrapping is coming from)
temp.menu = HMENU
temp.menu {
1 = TMENU
1 {
wrap = <ul class="level1">|</ul>
NO = 1
NO {
wrapItemAndSub = <li class="lev1">|</li>
}
}
2 < .1
2 {
wrap = <ul class="level2">|</ul>
NO.wrapItemAndSub = <li class="lev2">|</li>
}
3 < .2
3 {
wrap = <ul class="level3">|</ul>
NO.wrapItemAndSub = <li class="lev3">|</li>
}
}
.
EDIT: after clarification of problem:
working with LOADREGISTER in menus would result in a mess as the menu items are not generated inline recursive.
If you want to repeat the menuitem you should generate it in place.
Therefore you need to split the clean wrappings and use soem enhanced menu magic.
temp.menu = HMENU
temp.menu {
1 = TMENU
1 {
wrap = <ul class="level1">|</ul>
NO = 1
NO.wrapItemAndSub = <li>|</li>
// only for menuitems which contains further pages:
IFSUB < .NO
IFSUB {
// beginning the part of the submenu
after.cObject = TEXT
after.cObject {
field = nav_title // title
wrap = <div class="dropdown-menu"><ul><li>|</li>
}
}
}
2 < .1
2 {
// no beginning in wrap needed as it is done at level 1
wrap = |</ul></div>
}
}
further levels need additional handling. e.g.: 2.IFSUB > and 3.wrap = <ul>|</ul>
Note: If you want a clean html with indentions you need to use .noTrimWrap and multi line values in typoscript.

Adding sections (anchors) to a fluid menu in typo3 with bootstrap_package

I would like to have a menu mixing pages and sections from current page.
For example on page1:
section1_from_page1
section2_from_page1
page2
page3
And on page2:
section1_from_page2
page1
page3
Until now, all I'm able to do is to build a new section menu with TypoScript :
lib.sectionnavigation = HMENU
lib.sectionnavigation {
1 = TMENU
1 {
sectionIndex = 1
sectionIndex.type = header
sectionIndex.useColPos = -1
NO {
ATagBeforeWrap = 1
linkWrap = <span> | </span> <span class="bar"></span>
allWrap = <li> | </li>
allWrap.insertData = 1
}
}
special = list
special.value.data = page:uid
}
And then add this menu in the Main.html partials from bootstrap_package, with f:cObject :
<f:cObject typoscriptObjectPath="lib.sectionnavigation" />
However, that means that I have to maintain "format" (<li><span>...</span><span class="bar"></span></li>) in both the TypoScript and the Main.html partial which is not convenient.
For example, if I change the menu so that I don't need the bar class span, I'll have to update the partial and the TypoScript!
From what I've understood, bootstrap_package defines the main menu in setup.txt:
10 = TYPO3\CMS\Frontend\DataProcessing\MenuProcessor
10 {
levels = 2
includeSpacer = 1
as = mainnavigation
}
And then used this in the Main.html partial:
<f:for each="{mainnavigation}" as="mainnavigationItem">
My first plan was to try to built an new array (similar to the one in {mainnavigation}) using TypoScript but I couldn't find a way!
I also tried to use a MenuProcessor but didn't succeed either.
Any help would be really appreciated!
Thank you.
You should use the possibility to identify the current page in typoscript menus with the option to replace the complete rendering for a menu item.
The rendering for current page in a menu can be defined with ACT or CUR (ACT identifies all pages in the root line: current page, parent, grand parent, ...). In your case it may not differ, but you might play it safe:
lib.MainMenu = HMENU
lib.MainMenu {
wrap = <ul class="nav">|</ul>
1 = TMENU
1 {
NO {
wrapItemAndSub = <li><span> | </span> <span class="bar"></span></li>
}
CUR = 1
CUR.doNotShowLink = 1
// insert your section menu here:
CUR.before.cObject < lib.sectionnavigation
}
}

Typo 3 : Add H-menu first level li to class dynamic

I create menu for my site its working fine but now problem is that i want to add custom class to every li to first level.
My Typo script Below For menu i add class to every li but 2 li class call for all other except first and last. So have idea what need to do for it ?
lib.header_top_right = COA
lib.header_top_right {
10 = HMENU
10 {
wrap = <div class="menu-main-container">|</div>
entryLevel = 0
1 = TMENU
1 {
expAll = 1
wrap = <ul id="menu-main-1" class="main-nav">|</ul>
target = _top
NO {
wrapItemAndSub = <li class="home">|</li>|*|<li class="service">|</li>|*|<li class="contact">|</li>|*|<li class="l">|</li>|*|<li class="contact">|</li>
stdWrap.wrap = <span class="nav-title">|</span><span class="hr"> </span>
}
ACT < .NO
ACT = 1
CUR < .NO
CUR = 1
CUR {
stdWrap.wrap = <span class="nav-title">|</span><span class="hr"> </span>
}
}
}
}
Let's say you have three menu items for the first level. "Home", "Service" and "Contact".
Your optionsplit would work like that:
wrapItemAndSub = <li class="home">|</li>||<li class="service">|</li>||<li class="contact">|</li>
In general you can split the value (wrapItemAndSub in your case) in three parts with: |*|
first |*| middle |*| last
You could split each part with: ||
firstsubpart1 || firstsubpart2 |*| middlesubpart1 ...
There are 4 rules to do the split:
The priority is: last, first, middle
If the middle part is emtpy, the last part of the first is repeated
If the first and middle part is empty, the first part of the last gets repeated before the last
The middle gets repeated
You can find some examples and this explanation in the typo3 docs - optionsplit
Although you could reach your goal with the optionsplit, I wouldn't recommend it that way. If your sitestructure is and always will be fix, the optionsplit solution is ok. If your sitestructure changes and an additional link would be added to your first level you would have to change your typoscript for the menu. To "access" each first level menu via css you also could do something like this:
wrapItemAndSub= <li class="menu{field:uid}" id="menu{field:uid}">|</li>
wrapItemAndSub.insertData=1
The result would be something like:
<li class="menu1" id="menu1">Home</li>
<li class="menu2" id="menu2">Service</li>
<li class="menu3" id="menu3">Contact</li>

Id counting in TYPO3 menu using register:count_MENUOBJ

I made the menu in TYPO3 for bootstrap framework. Everything working just fine, but I have problem with counting the id element using register:count_MENUOBJ. The whole menu is constructed from two parts - main menu and sub menu:
page = PAGE
page.10 = HMENU
page.10.special = directory
page.10.entryLevel = 0
page.10.maxItems = 6
page.10 {
1 = TMENU
1 {
wrap = <div class="row"><ul class="nav nav-tabs pull-right" id="myTab" role="tablist">|</ul></div>
noBlur = 1
expAll = 1
NO {
ATagTitle.field = title
wrapItemAndSub = <li class="dropdown">|</li>
stdWrap.htmlSpecialChars = 1
accessKey = 1
}
IFSUB < .NO
IFSUB = 1
IFSUB {
wrapItemAndSub = <li class="dropdown">|</li>
linkWrap= |
ATagParams = role="button" data-toggle="collapse" data-target="#item-{register:count_MENUOBJ}"
ATagParams.insertData = 1
ATagBeforeWrap = 1
stdWrap.htmlSpecialChars = 1
}
ACTIFSUB < .IFSUB
ACTIFSUB {
wrapItemAndSub = <li class="active dropdown">|</li>
}
ACT < .NO
ACT = 1
ACT {
wrapItemAndSub = <li class="active">|</li>
}
CURIFSUB < .IFSUB
CURIFSUB = 1
CURIFSUB {
wrapItemAndSub = <li class="active dropdown">|</li>
}
}
}
page.20 = HMENU
page.20.special = directory
page.20.entryLevel = 0
page.20.maxItems = 6
page.20 {
1 = TMENU
1 {
wrap = <div class="row"><div class="tab-content">|</div></div>
noBlur = 1
expAll = 1
NO.doNotShowLink = 1
}
# second level
2.maxItems = 5
2 = TMENU
2.stdWrap.wrap = <div class="tab-pane fade in active pull-right" id="item-{register:count_MENUOBJ}"><nav class="navbar navbar-default pull-right submenu" role="navigation"><ul class="nav navbar-nav in">|</ul></nav></div>
2.stdWrap.wrap.insertData = 1
2{
expAll = 1
NO{
ATagTitle.field = title
wrapItemAndSub = <li>|</li>
}
IFSUB = 1
IFSUB{
ATagTitle.field = title
wrapItemAndSub = <li>|</li>
}
}
}
In the first menu block links has the correct value: data-target="#item-1", data-target="#item-2" etc..
In the second block the all links are generated in this form: id="item-5" staring and ending on item-5
Any suggestions?
register:count_MENUOBJ is counting the menu-items in the context where it's used.
In the first menu it's used in the context of the main-items and therefore counting in the natural order of the menu-items like an index. This might be the reason that the function of register:count_MENUOBJ is still confusing, even usable in that context.
In the second menu register:count_MENUOBJ is used in the context of the sub-menu items and counting the sub-items on level 2. So if on level two are 3 sub-items the register is 3. If 5 sub-items it's 5. In this context register:count_MENUOBJ is not usable as index as the amount of sub-items never reflects the expected value according to the question.
Therefore to get unique id's it's common practice to use p{field:uid} for pages or for content-elements c{field:uid}.
Example:
...
NO.wrapItemAndSub = <li id="nav-main-p{field:uid}">|</li>
NO.wrapItemAndSub.insertData = 1
...
Another alternative is to use register:count_MENUOBJ in the second menu also on the first level. Question if the menu in the question would have the required properties then.
Use the MenuProcessor instead of HMENU. I always had problems with the custom rendering of HMENU and than i turned to MenuProcessor because the html markup may be created directly in fluid.
Typoscript:
page = PAGE
page.10 = FLUIDTEMPLATE
page.10 {
...
dataProcessing {
10 = TYPO3\CMS\Frontend\DataProcessing\MenuProcessor
10 {
as = navigationMain
}
}
}
FLUID:
<f:for each="{navigationMain}" as="menuItem">
<!-- There you have access to menu items -->
</f:for>
Documentation: https://docs.typo3.org/typo3cms/SitePackageTutorial/MainMenuCreation/Index.html
In general #David already gave all relevant information.
For clarification and as hint for an easier implementation:
In your example you used the count register in page.20.2.stdWrap.wrap. this Wrap is executed in context of second level menu, but after the menu is allready generated, so it contains the number of elements in this menu level.
You need to use the count register in first level, and so it is a wrap to the second level you can use it in .1.IFSUB.wrapItemAndSub, as you have no content in first level it will be a wrap only for the second level menu.
And also mentioned from #David:
You also could use the uids from the pages itself.
Use it in page.10, and in page.20.2 you could use the field pid from any page on that level.
As you want to use it out of the context of a menuItem you might get the problem: there is no real field pid. Either you do the wrap on the first page/ menuItem (hint: optionsplit) or do it in the first level again.
(I doubt that for .1.stdWrap you are in the context of the first level page, so you could use field uid.)
you probably have to insert the following (not tested):
page.15 = RESTORE_REGISTER
just before page.20 = HMENU ... normally used in combination with LOAD_REGISTER but it looks as if your second HMENU has the count_MENUOBJ stuck at the last value of the first ...

Getting Pagecontent in HMENU

i'm creating a menu with HMENU in Typoscript. Now my question: is there a possibility to check if the linked paged as any content. if it has none how can i disable the link?
i'm generate the menu with the following code
NAV = HMENU
NAV{
entryLevel = 0
wrap = <ul class="nav">|</ul>
1 = TMENU
1.NO {
allWrap = <li class="nav-button"><p class="title">|</p></li>
}
1.ACT = 1
1.ACT {
allWrap = <li class="nav-button selected"><p class="title">|</p></li>
}
}
Untested!
You can check with numRows if there is any tt_content record on that page (you can use WHERE if you want to check only specific records). With required you define, that this menu item will only be rendered if numRows is greater then 1.
NAV.1.NO.allStdWrap.required.numRows {
table = tt_content
select {
# uid of this page, is the pid of the records to look for
pidInList.field = uid
}
}
NAV.1.ACT.allStdWrap < NAV.1.NO.allStdWrap