[TYPO3-dev] Add hook for generation of nav_title in tslib_menu ?

Tom Pfeiffer tpfeiffer at decadevolcano.net
Sat Jun 26 15:33:01 CEST 2010


Hi all,

this is a follow up to quite an old post: http://lists.typo3.org/pipermail/typo3-dev/2005-February/008434.html,
because as far as I can see never resulted in any new features in the core.


Many FE plugins use not-in-menu pages like "single view", "detail view" etc. 
In these cases, it would be great to have a simple way for the plugin to overwrite the nav_title of certain page uids, e.g. the current page.

First, an example from an extension that displays tours and where I modified tslib_menu to make that possible : 
http://hawaii.volcanodiscovery.com/hawaii/detailed_itinerary/HAW_KVS.html
shows a plugin in "detail view" on the general page with the nav_title "detailed itinerary", but the plugin replaces the nav title of that page in the rootline menu, by prepending it with a meaningful name, i.e. by the name of the tour, which looks much better than having just "detailed itinerary".


A proper solution sounds like having a hook in function "getPageTitle" of "tslib_menu.php", and we need a 3rd parameter $page_uid, which can be used by the hook to tell which page ID the menu item being rendered has:

function getPageTitle($title,$nav_title, $page_uid=0)    {
   # add hook for manipulation here, returns the new new $nav_title
	$nav_title = ... hook function ... 
	return strcmp(trim($nav_title),'') ? $nav_title : $title;
}

In the example above, I simply make sure that the plugin renders before the menu (in TS setup) and then use the GLOBALS['TSFE']->register to store a value for the overriding nav_title.
I added the page uid as parameter into the getPageTitle() function, in its definition and where it is called (2 times) in the code, then added a the following line to the function to check for a possible override:

function getPageTitle($title,$nav_title, $page_uid=0)    {
	if ($GLOBALS['TSFE']->register['OVERRIDE_NAVTITLE'][$page_uid]) $nav_title = $GLOBALS['TSFE']->register['OVERRIDE_NAVTITLE'][$page_uid];
	return strcmp(trim($nav_title),'') ? $nav_title : $title;
}
In the plugin, I simply set $GLOBALS['TSFE']->register['OVERRIDE_NAVTITLE'][$GLOBALS['TSFE']->id] = $row['title'];

Although simple, I'm aware this is probably not a good and clean solution... 
But I hope that someone of the t3 developers might be interested in adding this functionality, which I'm sure will benefit many websites.


Greetings,
Tom









More information about the TYPO3-dev mailing list