How to get destination uid in sectionIndex menu in TYPO3? - typo3

I need to generate a sectionIndex with the following structure:
<div data-magellan-expedition="fixed">
<dl class="sub-nav">
<dd data-magellan-arrival="c123">Build with HTML</dd>
<dd data-magellan-arrival="c124">Arrival 2</dd>
</dl>
</div>
My problem is that I do not know how to set the correct value for the data-magellan-arrival property. How can I retrieve the uid of the current item in the menu?
My TypoScript currently looks like this:
lib.cb_foundation.magellan = HMENU
lib.cb_foundation.magellan {
1 = TMENU
1 {
sectionIndex = 1
sectionIndex.type = header
sectionIndex.useColPos = 0
wrap = <div data-magellan-expedition="fixed"><dl class="sub-nav"> | </dl></div>
NO {
allWrap = <dd data-magellan-arrival="c{field:uid}"> | </dd>
allWrap.insertData = 1
}
}
special = list
special.value.data = page:uid
}
However, {field:uid} gives me the uid of the content element that uses this TypoScript, not the uid of the destination section element.

Use {field:sectionIndex_uid} instead of {field:uid}. There is a small hint at the bottom of tsref.

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.

TYPO3 Render content from subpages via typoscript

i am new to typoscript. I tried to render content from some subpages on an archive page.
I am not sure why my code is displaying nothing.
Firstly I am trying to iterate through my subpages
within that code
stdWrap.wrap = <div class="row"> | </div>
table = pages
select {
orderBy = sorting
# If this element is inserted as sitemap, consider the startingpoint
pidInList.field = uid
#max = 1
begin = 0
}
Secondly i am itarating through my tt_content table and trying to get the value of the column header and render that on my archive page.
The Code is working until
<div class="row"> | </div>
Full Code here:
lib.content = COA
lib.content {
stdWrap.wrap = <div class="row"> | </div>
table = pages
select {
orderBy = sorting
# If this element is inserted as sitemap, consider the startingpoint
pidInList.field = uid
#max = 1
begin = 0
}
renderObj = COA
renderObj {
stdWrap.wrap = <div class="testfestinner"> | </div>
10 = CONTENT
10.wrap = <h3>|</h3>
10 {
table = tt_content
select {
pidInList.field = uid
where = colPos = 212
orderBy = sorting
}
renderObj = COA
renderObj.10 = TEXT
renderObj.10.field = header
}
}
}
I am not sure where and how to debug that code.
Thanks in advance.
Something like table = pages can not be assigned to a COA directly.
You need a cObject of the type CONTENT for that purpose. Just like the one you assigned to the renderObj.

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
}
}

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">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
}

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 ...