Search code examples
typo3typoscript

TYPO3 - Previous and Next page


I have a set of pages which are siblings in the pagetree. I have 2 links to the next and previous page on top, and I want to add a class="prev" to the links that take you to the previous page, and "next" to the link that takes you to the next page. This is my code:

page.10.marks.MAIN.20 = HMENU
page.10.marks.MAIN.20{

    includeNotInMenu = 1
    excludeUidList = 78

    special = browse
    special{
        items = prev|next
    }

    1 = GMENU
    1 {
        wrap = <div class="ref-navi-wrapper clearfix">|</div>
        submenuObjSuffixes = a |*|  |*| b

        NO = 1
        NO {
            ATagParams = class="ref-nav prev" |*| |*| class="ref-nav next"
            ATagTitle.field = title

            altImgResource{
                width = 114
                import = uploads/media/
                import{
                    field = media
                    listNum = 0
                }
            }
        }
    }
}

The problem with this code is that in the last page, since there is only one link to the previous page, it takes the class "next", not "prev".

How could I solve this?


Solution

  • You can make a condition and use {register:count_MENUOBJ}:

    That means:

      ATagParams = class="ref-nav prev"
      ATagParams.override = class="ref-nav next"
      ATagParams.override {
        if.equals.dataWrap = {register:count_MENUOBJ}|
        if.value = 2
      }