4

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.

sarnold
  • 102,305
  • 22
  • 181
  • 238
oopbase
  • 11,157
  • 12
  • 40
  • 59

3 Answers3

7

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";';
}
Fedir RYKHTIK
  • 9,844
  • 6
  • 58
  • 68
  • I like this option better, it also works in extensions which don't have an own BE module. – Mateng Apr 13 '15 at 16:23
  • Should use `\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath()` to have a solution that does not rely on the instance being on the "root" of the domain. – pdu Mar 29 '16 at 12:55
6

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');
oopbase
  • 11,157
  • 12
  • 40
  • 59
1

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)

Mihir Bhatt
  • 3,019
  • 2
  • 37
  • 41