-
-
Save julrich/d91c1ac1968418e6ae8290f2a2e90afb to your computer and use it in GitHub Desktop.
I have another solution for the cache problem of logged in feusers:
lib.menu.cache {
key.cObject = COA
key.cObject.10 = TEXT
key.cObject.10.value = lib_menu_site{$page.uid.root}_lang{TSFE:sys_language_uid}
key.cObject.10.insertData = 1
key.cObject.20 = TEXT
key.cObject.20.data = TSFE:fe_user|user|usergroup
key.cObject.20.wrap = _groups|
key.cObject.20.insertData = 1
key.cObject.20.replacement.10.search = ,
key.cObject.20.replacement.10.replace = -
key.cObject.20.if.isTrue.data = TSFE:fe_user|user|usergroup
lifetime = default
}
Ah, that's really useful. Dynamic content as part of the cached menu is a common challenge here (e.g. show some part of the menu for logged in users only. Especially if you don't want to lose the performance gains completely for those cases.
Instead of using my constants {$page.uid.root}, I use {leveluid:0} now.
# Limit the L parameter to the possible language IDs!!!
# If not, a hit to an unused L parameter will write the cache for the default language E.G.:
config.linkVars = L(1-3)
lib.menu = COA
lib.menu.cache {
key.cObject = COA
key.cObject.10 = TEXT
key.cObject.10.value = lib_menu_site{leveluid:0}_lang{TSFE:sys_language_uid}
key.cObject.10.insertData = 1
key.cObject.20 = TEXT
key.cObject.20.if.isTrue.data = TSFE:fe_user|user|usergroup
key.cObject.20.data = TSFE:fe_user|user|usergroup
key.cObject.20.wrap = _groups|
key.cObject.20.insertData = 1
key.cObject.20.replacement.10.search = ,
key.cObject.20.replacement.10.replace = -
lifetime = default
}
And another nice gotcha. Should probably start revisiting our current implementation... ;)
In order to avoid listing of all pages where the resulting regular expression would be empty, like it is here done
[globalVar = TSFE:id={$page.uid.root}] || [globalVar = TSFE:id={$page.uid.404}] || [globalVar = TSFE:id={$page.uid.noTranslation}] || [globalVar = TSFE:id={$page.uid.search}]
maybe the better solution would be
page.stdWrap.replacement.10 {
search.cObject = COA
search.cObject.10 = HMENU
search.cObject.10 {
....
stdWrap.ifEmpty.cObject = TEXT
stdWrap.ifEmpty.cObject.value = somethingwhatever
stdWrap.wrap = #(|)#i
}
....
}
works for me, at least :)
This is based on: https://gist.github.com/pgampe/cb29bc0fc1111d1370cc
It's generalised to work for 'current' and 'active' classes, and menus of variable depth (max depth 5).
Also handles cases like the special pages (index page, search page, pages not inside the root node of the menu, where the replacement RegExp otherwise would be an empty string, replacing everything), logged in users and languages.