Martin
Martin

Reputation: 267

How to dynamicly load files with TypoScript

I want to load for every page the riht criticalCSS File.

So I saved them like this:

fileadmin/critical1.css for TSFE:id=1

fileadmin/critical2.css for TSFE:id=2

and so on. As there are a lot of pages I want the TS to be completely dynamic and NOT like this:

[globalVar = TSFE:id=1]
page {
  cssInline {
    10 = FILE
    10.file = fileadmin/critical1.css
  }
}
[global]

I want it like this:

page {
  cssInline {
    10 = FILE
    10.file= fileadmin/critical{page:uid}.css
  }
}

or this

page {
  cssInline {
    10 = FILE
    10.file= fileadmin/critical$GLOBALS['TSFE']->id.css
  }
}

But it is not working like this. Does anyone know how to do this?

Upvotes: 1

Views: 353

Answers (1)

Ravi Sachaniya
Ravi Sachaniya

Reputation: 1633

You just need to add the insertData = 1.

Check this code :

page {
  cssInline {
    10 = FILE
    10.file= fileadmin/critical{page:uid}.css
    10.file.insertData = 1 
  }
}

Reference : https://docs.typo3.org/typo3cms/TyposcriptReference/Functions/Stdwrap.html?highlight=insertdata#insertdata


Alternatively you can achieve it using headerData.

Check this code :

page {
  headerData {
    10 = TEXT
    10.value = {page:uid}
    10.insertData = 1 
    10.wrap = <link rel="stylesheet" type="text/css" href="fileadmin/critical|.css" media="all" />
  }
}

Reference : https://docs.typo3.org/typo3cms/TyposcriptReference/Setup/Page/Index.html#headerdata

Hope this helps you!

Upvotes: 4

Related Questions