Dynamically split a menu in 2 parts

Submitting your vote...
Rating: 4.9 of 5. 7 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 21: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 11: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 10: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 11: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 05: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 08: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

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

Latest comments

17-May-2013 10:09:34
Nicolas schrieb: If an extension or orther return a content empty, this solution not working. I not have the...
Wrap only if not empty
22-Apr-2013 12:08:26
morkel schrieb: hi i am new on typ03 and want to open a form on lightbox. when we click on image their a form will...
Using lightbox without extension
04-Mar-2013 13:33:47
Sebastian schrieb: Vergesse das immer wieder. Vielen Dank an dich und an Google :)
Wrap only if not empty
Deutsch
Search: