How to customize page according to its order in TYPO3?

315 Views Asked by At

Working on TYPO3 4.7 with Templavoila 1.7.0, I need a way to customize one value of the template according to the order of the current page in its navigation level.

In specific, I need to change the class attribute of a div to "left" or "right" if its even or uneven. Is there a way to do this with maybe a Templavoila Typoscript-Attribute?

For an example:

  • Main Page
    • Page 1
      1. Page 1.1 -> When rendering this page I want to set the class attribute to "left"
      2. Page 1.2 -> "right"
      3. Page 1.3 -> "left"
      4. Page 1.4 -> "right"
    • Page 2
    • Page 3

Thanks!

1

There are 1 best solutions below

1
On

A TemplaVoila TypoScript Attribute would fail, if someone change the sorting of the pages.

I would try to render a menu. With allWrap.cObject = TEXT it should be possible to override the output. So just create a menu which renders the class, and depending on even or odd render the class you need.

!pseudo-code!

lib.getClass = HMENU
lib.getClass {
  1 = TMENU
  1.NO = 1
  1.NO {
    allWrap.cObject = TEXT
    allWrap.cObject.value = left
    allWrap.cObject.override = right
    allWrap.cObject.override {
      if.value = 1
      if.equals.data = REGISTER:count_HMENU_MENUOBJ
      if.equals.stdWrap.wrap = |%2
      if.equals.prioriCalc = 1
    }
  }
}

Did not test the code, so if it does not work, check for syntax. Probably deactivate override, check the value REGISTER:count_HMENU_MENUOBJ but i guess it should be the register you need.