Create menus using data from other tables than "pages"

Submitting your vote...
Rating: 4.3 of 5. 3 vote(s).
Click the rating bar to rate this item.

Here's a little PHP codesnippet that allows you to use other tables than 'pages' to render menus.

What it does is adding a TS "select" property to the userFunc.. More info on "select" can be found in TSRef.

Tsref, select

 

Create a file in your "fileadmin" folder, and name it "menuFunc.inc", then fill the file with this content:

 

-- cut --

<?php

class user_menuFunc {

function makeMenuArray($content,$conf) {

$menuArr = array();

$lConf = $conf["userFunc."];

$res = $this->cObj->exec_getQuery($lConf["table"],$lConf["select."]);

if ($error = $GLOBALS['TYPO3_DB']->sql_error()) {

$GLOBALS['TT']->setTSlogMessage($error,3);

} else {

$GLOBALS['TT']->setTSlogMessage('NUMROWS: '.$GLOBALS['TYPO3_DB']->sql_num_rows($res));

while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {

$menuArr[] = $row;

}

}

return $menuArr;

}

}

?>

-- cut --

 

And here's a simple example using the function to create a list of tt_address records in a standard TMENU. (Which could also have been a GMENU)

 

BTW: Remember to change the "select" statement in the line:

 

lib.usermenu.special.userFunc.select.pidInList = 4

 

to point to the sysfolder where your tt_address records are located..

 

page.includeLibs.usermenu = fileadmin/menuFunc.inc

lib.usermenu = HMENU
lib.usermenu.special = userfunction
lib.usermenu.special.userFunc = user_menuFunc->makeMenuArray
lib.usermenu.special.userFunc.table = tt_addess
lib.usermenu.special.userFunc.select.pidInList = 4
lib.usermenu.1 = TMENU
lib.usermenu.1 {
  NO {
    doNotLinkIt = 1
    stdWrap.field = user
    # Remove the # from the next line if you want to see which fields are available!
    #stdWrap.data = debug:data
    typolink.parameter.field = www
    allWrap = <br>
  }
}

 

 

This snippet was submitted by Peter Klein



Comments


Patrick, 08-06-06 16:00:
Under Typo3 version 4.0 and with TemplaVoila 1.0.1 I had to change the last lines to:
NO {
# doNotLinkIt = 1
stdWrap.data = field:name
# Remove the # from the next line if you want to see which fields are available!
#stdWrap.data = debug:data
typolink.parameter.data = field:www
allWrap = <br>
}

Also the following line:
lib.usermenu.special.userFunc.table = tt_addess
should obviously be:
lib.usermenu.special.userFunc.table = tt_address

Thanks for sharing this one Peter!
Peter, 14-05-07 16:45:
Another usage of the script.
This will convert the TYPO3 "Sectionmenu" (which is not a real menu, but just a select query in the tt_content database.), into a real HMENU with optionSplit etc.

-- cut --
page.includeLibs.usermenu = fileadmin/menuFunc.inc

tt_content.menu.20.3 >
tt_content.menu.20.3 = HMENU
tt_content.menu.20.3 {
special = userfunction
special.userFunc = user_menuFunc->makeMenuArray
special.userFunc.table = tt_content
special.userFunc.select.andWhere = sectionIndex!=0 AND header!=''
special.userFunc.select.pidInList.override.field = pages
wrap = <div class="csc-menu csc-menu-3">|</div>
1 = TMENU
1.NO.doNotLinkIt = 1
1.NO.stdWrap.field = header
1.NO.stdWrap.typolink.parameter.field = pid
1.NO.stdWrap.typolink.section.field = uid
1.NO.stdWrap.htmlSpecialChars = 1
1.NO.allWrap = <p class="csc-section">[1]|</p> |*| <p
class="csc-section">[2]|</p> |*| <p class="csc-section">[3]|</p>
}
-- cut --

Add comment

* - required field

*



*
*

Top 10 Updates

Nice fonts using Google font API geändert am  20-May-2010 16:36:47
TS-based Searchbox for Indexed Search  geändert am  18-May-2010 18:27:15
TYPO3 SEO geändert am  30-Apr-2010 09:44:22
Search engine friendly graphical headers in TYPO3 geändert am  30-Apr-2010 09:33:44
Creating a simple Infocenter using TYPO3 geändert am  17-Nov-2009 12:12:52
Making the Section Menu work correctly with TemplaVoila geändert am  05-May-2009 12:27:17
Show pages with type "Not in Menu" in a sitemap geändert am  05-May-2009 12:11:17
Implementation of the DHTML menu from brainjar.com  geändert am  01-Feb-2009 14:02:48
Sample DHTML menu geändert am  01-Feb-2009 13:51:25
A introduction to the CONTENT object geändert am  26-Jan-2009 13:20:39

Latest comments

21-Jan-2012 20:22:24
jemmkwc jemmkwc schrieb: MOGWOX , [url=http://prdpuhwzxyrc.com/]prdpuhwzxyrc[/url],...
fe_useradmin form does not save
20-Jan-2012 20:35:32
fsivjktiuld fsivjktiuld schrieb: idCmnv <a href="http://gakbrrkrxhye.com/">gakbrrkrxhye</a>
fe_useradmin form does not save
19-Jan-2012 18:05:25
bvffee bvffee schrieb: jl2vQt , [url=http://xcinvpbclrbm.com/]xcinvpbclrbm[/url],...
External links and shortcuts directly in the menu
Deutsch
Search: