Dynamically split a menu in 2 parts

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

This snippet dynamically splits the menu in 2 parts.

So the 1st part contains the 1st half of the menuitems and the 2nd part contains the 2nd half of the menuitems.

 

1st part

<menuitem1>

<menuitem2>

<menuitem3>

 

2nd .part

<menuitem4>

<menuitem5>

<menuitem6>

 

TYPOScript:

 

lib.splitmenu = COA
lib.splitmenu {
   
  10 = HMENU
  10.special = directory
  10.special.value = 1
  10.1 = TMENU
  10.1 {
    wrap = <div>1st part<br>|</div>
    NO {
      stdWrap.cObject = COA
      stdWrap.cObject {
        10 = TEXT
        10.field = title
        if.value.data = register:count_HMENU_MENUOBJ
        if.negate = 1
        if.isLessThan.prioriCalc=1
        if.isLessThan.cObject=TEXT
        if.isLessThan.cObject.insertData=1
        if.isLessThan.cObject.value = ({register:count_menuItems}+1)/2
        wrap = |<br>
      }
    }
  }
  20 < .10
  20.1.wrap = <div>2nd part<br>|</div>
  20.1.NO.stdWrap.cObject.if.negate >
}

page.200 < lib.splitmenu

 

 

This snippet was submitted by Peter Klein




Comments


Udo, 29-10-06 22:00:
This one looks good but creates empty link entries (links to the pages without link labels). Any ideas to fix this?
François, 28-06-07 13:17:
The following snippet does not generate empty links nor empty wraps:

lib.splitmenu = COA
lib.splitmenu {
10 = HMENU
10 {
special = directory
special.value = 1
1 = TMENU
1 {
wrap = <div>1st half of menu items<br />|</div>
NO {
allStdWrap {
wrap = |<br />
if {
value.data = register:count_HMENU_MENUOBJ
negate = 1
isLessThan {
prioriCalc = 1
cObject = TEXT
cObject.insertData = 1
cObject.value = ({register:count_menuItems} + 1) / 2
}
}
}
stdWrap.if < .allStdWrap.if
}
ACT < .NO
ACT = 1
ACT.stdWrap.wrap = <strong>|</strong>
}
}
20 < .10
20.1.wrap = <div>2nd half of menu items<br>|</div>
20.1.NO.stdWrap.if.negate >
20.1.NO.allStdWrap.if.negate >
20.1.ACT.stdWrap.if.negate >
20.1.ACT.allStdWrap.if.negate >
}

Enjoy!
hua, 15-04-08 12:18:
I have a question, can you give me answer?
if the menu has child menuitems, how to write the ts using this method. thanks.
Paul, 30-06-08 13:11:
Small correction to the above: +1 should be +2 throughout to make sure the 'weighting' of menu items is correct (i.e. always more items in the first two columns)
Paul, 10-07-08 07:29:
You can use the same approach to output a menu split into 3 parts too. Requires a bit more playing with \\'if\\' though. lib.splitmenu = COA lib.splitmenu { 10 = HMENU 10 { includeNotInMenu = 1 special = directory special.value = 1 1 = TMENU 1 { wrap = <ul>|</ul> NO { ATagParams = ATagBeforeWrap = 1 ATagTitle.field = title ATagTitle.noTrimWrap = |Link to: | | stdWrap.htmlSpecialChars = 1 allStdWrap { wrap = <li>|</li> if { value.data = register:count_HMENU_MENUOBJ negate = 1 isLessThan { prioriCalc = 1 cObject = TEXT cObject.insertData = 1 cObject.value = ({register:count_menuItems}+2) / 3 } } } stdWrap.if < .allStdWrap.if } ACT < .NO ACT = 1 ACT.stdWrap.wrap = <strong>|</strong> } } 20 < .10 20.1.NO.allStdWrap.if { negate = 0 isLessThan.cObject.value = ({register:count_menuItems}+2) / 3 isGreaterThan < .isLessThan isGreaterThan.cObject.value = (({register:count_menuItems}+1) /3) *2 } 20.1.NO.stdWrap.if < .20.1.NO.allStdWrap.if 20.1.ACT < .20.1.NO 30 < .10 30.1.NO.allStdWrap.if { isGreaterThan < .isLessThan isGreaterThan.cObject.value = (({register:count_menuItems}+1) /3) *2 isLessThan > } 30.1.NO.stdWrap.if < .30.1.NO.allStdWrap.if 30.1.ACT < .30.1.NO } The \\'+2\\' on the isLessThan for the first \\'group\\' of menu items is a lame way of making sure the first column or group has more items than the subsequent ones... there\\'s probably a better / more mathemetical way to do it but this is ok for me
Brian Hauge, 06-07-10 10:34:
Both examples give me an empty line before each menuitem, with an A tag of the same id as the active one.

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

20-Aug-2010 16:31:13
pritam schrieb: Hello, Can any body tell me how to add the realurl in the typo3.
Articles
17-Aug-2010 15:25:30
Graham Solomon schrieb: I have developed a nice extension for using this Google Font API with TYPO3, along with their web...
Nice Fonts using Google font API
12-Aug-2010 17:39:44
Ritesh Jaiswal schrieb: I have added the above code into page template but it is not working. It only index the page into...
Index search
Deutsch
Search: