Your ads will be inserted here by
Easy AdSense.
Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.
Let’s assume we have an extension, e.g. a news extension my_news
that provides a list view of entries that can be filtered via categories via the query index.php?id=listViewID&tx_my_news['category']=categoryID
. In our navigation we want to create a submenu under the list view page, so that our navigation looks like this:
- Home
- News
- Category 1
- Category 2
- Category 3
- About us
- etc…
We can achieve this effect using stdWrap.cObject = CASE
on our TMENU_ITEM
:
lib.nav = HMENU lib.nav { #this is all basic knowledge to you entryLevel = 0 special = directory special.value = 1 1 = TMENU 1 { wrap = <ul>|</ul> expAll = 1 NO = 1 NO.wrapItemAndSub = <li>|</li> ACT < .NO } 2 < .1 2 { #from hereon it gets interesting wrap = <ul>|</ul> NO { stdWrap.cObject = CASE stdWrap.cObject { key.field = uid #default: render default menu default = TEXT default { field = title typolink.parameter.field = uid } #overwrite menu for news categories news = HMENU news { special = userfunction special.userFunc = Tx_MyNews_UserFuncs->news_menu special.targetPid = {$listViewID} 1 = TMENU 1 { NO = 1 NO.ATagTitle.field = title ACT = 1 ACT < .NO } 2 < .1 2 { wrap = <ul>|</ul> NO = 1 NO.wrapItemAndSub = <li>|</li> ACT < .NO } } } } ACT < .NO } } # stdWrap.cObject = CASE requires hardcoded PID... so inherit the template here for configuration ### lib.nav.2.NO.stdWrap.cObject.235 < lib.nav.2.NO.stdWrap.cObject.news lib.nav.2.ACT < lib.nav.2.NO |
The userfunction looks like this
class Tx_MyNews_UserFuncs { var $cObj; /** * Returns an array to render an HMENU for the news categories * * @param string $content * @param array $conf TypoScript configuration array * @return array news categories menu */ function news_menu ($content,$conf) { $GLOBALS['TYPO3_DB']->store_lastBuiltQuery = 1; // prepare db statements $table = 'tx_mynews_domain_model_category'; $fields = 'title, uid'; $where = ''; $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, $where); $title = $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery; $category_menu = array( ); while ( ($category = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) ) { // build category link $linkConf = array ( 'useCacheHash' => true, 'parameter' => $conf['targetPid'], 'additionalParams' => '&tx_my_news[category]=' . $category['uid'] ); $link = $this->cObj->typolink_URL( $linkConf ); // add to menu $category_menu[] = array ( 'title' => $category['title'], '_OVERRIDE_HREF' => $link ); } $link = $this->cObj->typolink_URL( array( 'parameter' => $conf['targetPid'] ) ); return array ( array ( 'title' => 'News', '_OVERRIDE_HREF' => $link, '_SUB_MENU' => $category_menu ) ); } } |
Thenk you!
Looks like exactly what I’m looking for, I will try that. Does it also recognize ACT or CUR states?
It probably should.
Keep in mind, though, that this is a bit dated, so the TYPO3-interface might have changed a bit since then. I haven’t done a lot of TYPO3-related work for a while so you’re on your own here ;).