I have the issue that one of the pages in a TYPO3 (11.5.20) environment contains dozens of subpages, which would overly extend the HMENU
displayed on the frontend. The suggestion by a colleague was to hide all the subpages in said menu and instead display them on a separate menu embedded on the page itself. This basically means we have to make the subpages hidden for only one specific menu, not for all of them, ruling out the possibility to hide the subpages for navigation by the backend.
To have this functionality not just applying to a single, statically defined page, my idea to approach this would be to register a separate page layout for pages with this requirement and somehow configure HMENU
in Typoscript to ignore subpages of that given layout. What I found is the itemArrayProcFunc
for processing menu arrays; what I would do is to simply return an empty array with it if said page layout applies. I am encountering two problems though:
- The function I have defined seems not to get called. I am including the script like in the Typoscript snippet below, but even when deliberately throwing an exception inside, there is no feedback on it whatsover by TYPO3, with the menu displaying all pages as usual. Is that method of inclusion possibly outdated? The official TYPO3 doc dictates
USER
andUSER_INT
for registering custom functions, but I’m not exactly sure how to make this work together withitemArrayProcFunc
. - Even if the function worked, I’m not sure how to retrieve the layout of the respective parent page, or if it is even possible to retrieve it at all.
I’m assuming there are some major points regarding custom functions within Typoscript I might have missed (to be fair though – TYPO3’s documentation is not exactly transpicuous). Could anyone possibly give me a hint on it? Is there maybe even a more elegant way to hide menus from specific pages?
lib.ts
(snippet):
includeLibs.user_menuItemArrayProcFunc = EXT:lraffb_intern/Classes/MenuItemArrayProcFunc.php
lib {
...
20 = HMENU
20 {
stdWrap {
outerWrap = <nav class="navigation">|</nav>
}
entryLevel = 0
1 = TMENU
1 {
wrap = <ul>|</ul>
NO = 1
NO {
allWrap = <li>|
wrapItemAndSub = |</li>
itemArrayProcFunc = user_menuItemArrayProcFunc->process
}
ACT < .NO
ACT {
allWrap = <li class="act">|
}
}
2 < .1
3 < .2
4 < .3
5 < .4
}
...
}
MenuItemArrayProcFunc.php
:
<?php
class MenuItemArrayProcFunc {
public function process($menuArr, $conf) {
if (PAGE_LAYOUT == 'pagets__left_no_subpages') // retrieve the page layout here somehow
return [];
return $menuArr;
}
}
2
Answers
Well – actually this is the solution you are looking for but just the other way around. Set those pages to
hide in menus
and then use theincludeNotInMenu
parameter to still use them in all menus except the one you mentioned.https://docs.typo3.org/m/typo3/reference-typoscript/main/en-us/ContentObjects/Hmenu/Index.html#includenotinmenu
Depending on a flag (that could be the page layout) you should differ the rendering of menus. That would be easy if you render your menus with FLUID as you can insert conditions in an easier way than in TypoScript.
e.g.: Depending on your condition you render the second level or skip it.
On page rendering you have all fields from
pages
record, including your flag. When you call the menu partial just remember to insert the flag in the arguments.