Dynamically change class attribute of body tag using typoscript

This is a small note about how we can change the class attribute of body tag using typoscript.

# bodyTag
page.bodyTag >

page.bodyTagCObject = TEXT
page.bodyTagCObject.data = levelfield:-1 :, myfeildname, slide
page.bodyTagCObject.wrap = <body class="myclass_|">

Well here I am using a custom field added to pages table. If you wish to use the page id you may try using this code below:

# bodyTag
page.bodyTag >

page.bodyTagCObject = TEXT
page.bodyTagCObject.data = field:id
page.bodyTagCObject.wrap = <body class="myclass_|">

This way you may expect body tags like:
<body class="myclass_1">
<body class="myclass_2">

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

2 thoughts on “Dynamically change class attribute of body tag using typoscript”

  1. Are you referring to onclick or onload?
    I usually prefer Prototype / jQuery to bind all events.

    Anyway you should be able to use this method:

    # bodyTag
    page.bodyTag >

    page.bodyTagCObject = TEXT
    page.bodyTagCObject.data = field:id
    page.bodyTagCObject.wrap = <body onload=’javascript:myFunction();’ class=’myclass_|’>

  2. How would I add an onclick event using this method?

    page.bodyTag >

    page.bodyTagCObject = TEXT
    page.bodyTagCObject.wrap =

Comments are closed.