BarryWalsh
BarryWalsh

Reputation: 1340

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

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!

Upvotes: 6

Views: 16028

Answers (4)

Martin Krung
Martin Krung

Reputation: 1127

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 |>|   
    }
}

Upvotes: 5

Christian Michael
Christian Michael

Reputation: 2316

Since TYPO3 Version 9:

# Body Classes
[page["uid"] == 1]
  page.bodyTag = <body class="home">
[END]

Upvotes: 2

Mihir Bhatt
Mihir Bhatt

Reputation: 3155

Following will do

page.bodyTag >
page.bodyTagCObject = TEXT
page.bodyTagCObject.value= skin-blue 
page.bodyTagCObject.wrap = <body class="|">

Upvotes: 1

BarryWalsh
BarryWalsh

Reputation: 1340

Figured it out!

[globalVar = TSFE:id = 4]
page.bodyTag = <body class="page-speakers"> 
[end]

Upvotes: 8

Related Questions