Search code examples
javascripttypescripttypo3typoscript

Typo3 inlcudeJS only on specific pages


i tried various options to include a javascript file within the setup.typoscript file only for specific pages, but couldn't get it running. The idea is, that i can include script files only to specific pages with a specific ID. For example i tried:

[page ["uid"] == 5]
    page.30.includeJSFooter = EXT:polyrama_museum/Resources/Public/JavaScript/Src/startpage.js
[END]

Where i want the "startpage.js" file only loading on the page with the "uid" 5 (which is the startpage in my case). Also i put the top command at the very bottom of the setup file outside the page object, but also within the page {} object, it's not running. Can anybody please help me? That would be great, as i searched now for a solution long time.


Solution

  • Try this:

    [page["uid"] == 5]
        page.includeJSFooter.polyrama_museum_startpage = EXT:polyrama_museum/Resources/Public/JavaScript/Src/startpage.js
    [END]
    

    includeJSFooter is a property of PAGE (which I assume page is an instance of) and it's an array. The polyrama_museum_startpage key is just descriptive, so if you want to use something else you can.

    Also, I'm not sure if a space between page and ["uid"] is allowed