Reputation: 2982
I have a pagetree like this:
home
foo
foobar
foobaz
bar
barbar
contact
I want to show a navigation menu, that contains all subpages of the current page. I'm achieving this with this TypoScript
:
subNav = HMENU
subNav {
entryLevel = -1
1 = TMENU
1 {
wrap = <ul id="submenu">|</ul>
NO = 1
NO {
wrapItemAndSub = <li>|</li>
}
ACT = 1
ACT {
wrapItemAndSub = <li id="active">|</li>
}
}
}
But: When the current page has no subpages, then the subpages of the parent page should be shown.
Examples:
home
: The menu should show links to the pages foo
and bar
.foo
: foobar
and foobaz
should be shown.foobar
: Here also foobar
and foobaz
should be shown instead of an empty menu.Typo3 version is 7.6.
Upvotes: 1
Views: 3488
Reputation: 937
For the sake of completeness I wanted to mention that sometimes it‘s an option to think such problems "from front end".
E.g. if there are subpages with hide in menu set or other conditions that include or exclude pages from menu you‘ll get an empty menu unless you reproduce that in your entrylevel.override
. This can be avoided by using something like
lib.subMenu = HMENU
lib.subMenu {
entrylevel = -1
1 = TMENU
# ...
ifEmpty.cObject = HMENU
ifEmpty.cObject {
entrylevel = -2
1 = TMENU
# ...
}
}
This way you don‘t need to bother why your current page‘s menu is empty, the fact it is suffices. Can get a bit fiddly when it comes to wraps, though…
Upvotes: 1
Reputation: 2982
I could solve it. I had to set entryLevel
of the HMENU
to -1
if the current page has subpages. The -1
means: Start with che child pages of the current page. If the page has no subpages, the entryLevel
has to be set to -2
. That means: Start with the children of the parent page.
entryLevel
has a override
property:
lib.subMenu = HMENU
lib.subMenu {
1 = TMENU
1 {
wrap = <ul id="submenu">|</ul>
NO = 1
NO {
wrapItemAndSub = <li>|</li>
}
ACT = 1
ACT {
wrapItemAndSub = <li class="active">|</li>
}
}
// -1 = current page
entryLevel = -1
// Set entry level to -2 (this is the parent page), if the current page has
// no subpages.
entryLevel.override = -2
entryLevel.override.if {
negate = 1
isTrue.numRows {
table = pages
where = pid=this
}
}
}
Upvotes: 3
Reputation: 2683
This is a good question. At the moment I only see a solution with using the stdWrap-properties of entryLevel. So you could make a entryLevel.stdWrap.cObject = CONTENT
and then perform a select query on pages pidInRootline = current (default?). In the renderObj
of CONTENT you just return the entryLevel in case subpages are found and if not, the entryLevel of the next highest level.
Like this it should be possible but I hope that anyone has a better solution.
Upvotes: 1