Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typo3 Adding a class to the body tag on a specifc page

Tags:

typo3

I'm trying to figure out how conditionally add a class to the body tag of a specific page. I'm trying to do it via typoscipt but haven't been able to figure it out. Maybe there's a better way to do it though. The site is using Typo3 version 4.4.6

I've tried this which didn't work

page.4.bodyTag >
page.4.bodyTagCObject = TEXT
page.4.bodyTagCObject {
    field = uid
     wrap = <body class="uid-|">
}

Any help or pointers would be greatly appreciated!

like image 328
BarryWalsh Avatar asked Dec 01 '14 20:12

BarryWalsh


3 Answers

Figured it out!

[globalVar = TSFE:id = 4]
page.bodyTag = <body class="page-speakers"> 
[end]
like image 119
BarryWalsh Avatar answered Dec 14 '22 22:12

BarryWalsh


We use the follwing snippet for TYPO3 4.5 and TYPO3 6.2. Outputs class and id like this on every page. Just style your css.

<body id="pid13" class="be- rpid13 level1 no-subs">

Snippet to place into root setup:

page {
    bodyTagCObject >
    bodyTagCObject = COA
    bodyTagCObject {

        ### id of page in root level:
        10 = TEXT
        10.data = levelfield:1, uid
        10.dataWrap =  id="pid{TSFE:id}" class="be-{TSFE:beUserLogin} rpid|

        ### current level/depth of page
        20 = TEXT
        20.data = level:1
        20.noTrimWrap = | level| |

        ### if page has subpages
        30 = TEXT
        30.value = has-subs
        30.if.isTrue.numRows {
            table = pages
            where = pid=this
        }

        ### if page has NO subpages
        40 = TEXT
        40.value = no-subs
        40.if.negate = 1
        40.if.isTrue.numRows {
            table = pages
            where = pid=this
        }

        50 = TEXT 
        50.value = "

        stdWrap.noTrimWrap = |<body |>|   
    }
}
like image 21
Martin Krung Avatar answered Dec 14 '22 21:12

Martin Krung


Since TYPO3 Version 9:

# Body Classes
[page["uid"] == 1]
  page.bodyTag = <body class="home">
[END]
like image 30
Christian Michael Avatar answered Dec 14 '22 23:12

Christian Michael