0
votes

It there any way to apply special formatting for the menu item immediately after the current item, that is CUR + 1. Something like:

lib.menu = HMENU
lib.menu {
    1 = TMENU {
        NO = 1
        NO = {
            ...
        }
        ...
        # The currently selected item
        CUR = 1
        CUR {
            allWrap = ...
        }

        # The next item
        CUR + 1 = 1
        CUR + 1 {
            allWrap = ...
        }
    }
}

I would appreciate any feedback you might have. Also alternatives: Can write a PHP class/function instead of writing this in typoscript.

2

2 Answers

0
votes

Unfortunately this is not possible with just TypoScript. I don't really see a good solution with PHP really either. You could however do it with PHP, but you will need to load the same menu items like in your menu itself inside PHP. Which makes it very inefficient and not flexible at all.

I would say add a special class attribute to the link or wrap and perform your formatting with JavaScript. Where the item coming after the active one is modified.

0
votes

So I manage to solve this myself. The answers is to use a so-called register to mark if we've passed the current object or not. For example:

lib.menu = HMENU
lib.menu {
    1 = TMENU {
        NO = 1
        NO = {
            # Render using Common Object Array (COA)
            stdWrap.cObject = COA
            stdWrap.cObject {
                # Normal Case (However the an item should normally be rendered
                10 = TEXT
                10 {
                   if {
                       isTrue.data = register:cid
                       value = NORMAL RENDERING
                   }
                }
                20 = TEXT
                20 {
                   if {
                       isTrue.data = register:data
                       value = RENDERING (IMMEDIATELY) AFTER THE CURRENT ITEM
                   }
                }
                # Unset the register (after we've done with our special formatting)
                30 = LOAD_REGISTER
                30.cid= 0
            }
        }
        ...
        # The currently selected item
        CUR = 1
        CUR {
            # Render using Common Object Array (COA)
            stdWrap.cObject = COA
            stdWrap.cObject {
              # However the Current item should normally be rendered
              10 = TEXT
              10.field = title
              # Mark that we've reached the current item
              20 = LOAD_REGISTER
              20.cid= 1
            }    
        }     
    }
}

A register, set using LOAD_REGISTER, is basically a type of run-time variable, which can be set and reset in the course of iterating through the menu items (or whatever). As such it can be used to note our progress through the menu items, particularly noting if we've passed the current menu item (CUR) or not.

rant begin Hardly an elegant solution considering that typoscript is domain-specific language which is mainly used for this normatting stuff like menus./rant end