oopbase
oopbase

Reputation: 11415

Including CSS File in TYPO3 Backend?

I am trying to include my cascading style sheet into my TYPO3 extension. I created the extension with "kickstarter". This is the way I tried to include it:

$this->doc->getPageRenderer()->addCssFile(t3lib_extMgm::extRelPath('myExt') . 'res/css/my_stylesheet.css');

I added that line at the end of the main() method. So what am I doing wrong? The path including the file does definately exist.

Thank you.

Upvotes: 4

Views: 6669

Answers (3)

Mihir Bhatt
Mihir Bhatt

Reputation: 3155

Belo given trick will work for TYPO3 8.7.X version

Step-1 Add following lines in ext_tables.php file

$GLOBALS['TBE_STYLES']['skins'][$_EXTKEY]['name'] = $_EXTKEY;
$GLOBALS['TBE_STYLES']['skins'][$_EXTKEY]['stylesheetDirectories']['css'] = 'EXT:'.$_EXTKEY.'/stylesheets/visual/';

Step-2: Define css file with any name at the given path (in our case its 'stylesheets/visual/' inside the extension)

Upvotes: 1

Fedir RYKHTIK
Fedir RYKHTIK

Reputation: 9994

And if You would like to include CSS file in other module than Yours, without to modify it, You could use $TBE_STYLES array.

ext_tables.php:

// Custom CSS include
if (TYPO3_MODE=="BE")   {
    $TBE_STYLES['inDocStyles_TBEstyle'] .= '@import "/typo3conf/ext/your_ext/res/css/your.css";';
}

Upvotes: 7

oopbase
oopbase

Reputation: 11415

Ok, I could finally solve the problem.

When adding the code right after instancing the "doc" object, everything works fine.

$this->doc = t3lib_div::makeInstance('mediumDoc');
$this->doc->getPageRenderer()->addCssFile(t3lib_extMgm::extRelPath('myExt') . 'res/css/my_stylesheet.css');

Upvotes: 6

Related Questions