Typo3 Adding a class to the body tag on a specifc page
Asked Answered
C

4

6

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!

Caxton answered 1/12, 2014 at 20:33 Comment(0)
C
8

Figured it out!

[globalVar = TSFE:id = 4]
page.bodyTag = <body class="page-speakers"> 
[end]
Caxton answered 1/12, 2014 at 20:40 Comment(1)
You can combine your solution with your question and insert page.4.bodyTagCObject.insertData = 1 to insert the uid in the class.Poly
S
5

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 |>|   
    }
}
Sole answered 13/10, 2015 at 14:53 Comment(1)
great !! still valuable in 2024Distraction
S
2

Since TYPO3 Version 9:

# Body Classes
[page["uid"] == 1]
  page.bodyTag = <body class="home">
[END]
Sickler answered 12/8, 2020 at 18:56 Comment(0)
E
1

Following will do

page.bodyTag >
page.bodyTagCObject = TEXT
page.bodyTagCObject.value= skin-blue 
page.bodyTagCObject.wrap = <body class="|">
Epaulet answered 10/10, 2015 at 12:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.