$TBE_STYLES and custom css in TYPO3 backend

the most of this night went on to find out how to bring my own css file to the TYPO3 backend for my own extensions, which happen to be more and more BE modules. This is just readable fun of an oldschool try and error session.

The issue is, if you go and program stuff that makes your life in the backend more comfortable, you´d better go for it the real way. It has to look nice, at least as much as the skin of TYPO3 does itself. Speaking of this, I kinda like the way they´re going in 4.2. But I hate that the following line of code blows away all the “4.2 magic” and reveals you the historic 3.x backend interface style. Time to move on…


$TBE_STYLES['styleSheetFile_post'] = t3lib_extMgm::extRelPath($_EXTKEY).'myownway.css';

Doing so will overwrite the following commands, next to others. Imagine, how devastating this is.


@import "typo3-colors.css";
@import "typo3-alt-menu-php.css";
@import "typo3-alt-db-navframe-php.css";
@import "typo3-db-list-php.css";
@import "typo3-clipboard.css";
@import "typo3-alt-topmenu-dummy-php.css";
@import "typo3-alt-palette-php.css";
@import "typo3-TCEforms.css";
@import "typo3-dyntabmenu.css";
@import "typo3-index-php.css";
@import "typo3-tree.css";
@import "ext-cms-layout-db-layout-php.css";
@import "typo3-file-list.css";
@import "typo3-csh.css";
@import "typo3-workspaces.css";

So, THIS does not work. And don´t try this at home, it will shock you ;) You may try to reinvent another BE style at all (thus skipping on importing around 20 stylesheet files) but I am not going to do that.

Better stick on this following line in the ext_tables.php of your extension. It works for my purposes right now: it just adds a stylesheet file that comes packed with the ext when installing.

$TBE_STYLES['stylesheet2'] = t3lib_extMgm::extRelPath($_EXTKEY).'myownway.css';

Note that the css file in this case resides in the extension root folder. It works for one extension using this line of code. But if you have another one with the exact same command, there will only be one of the css files, but you might be expecting two of them. Well, how about guessing cool numbers that nobody else is going to use? (23, 42… any eleven digit prime number should work just fine)

It is understandable that the post-style is for having the important skin features included at last. That ensures that nobody else freaks out with the standard css commands for the backend. css is just so good. But how are we supposed to create a backend user experience that fits into the style, but with a touch of our own unique taste? It´s just humiliating to produce hardcoded html style attributes. ^^

Custom CSS, just include it

I ran into this problem this night, because I am developing two BE modules simultaneously, that can´t be fusioned to one in a semantic matter. Both should have got the css fanciness, but only the stylesheet2 field in $TBE_STYLES can be used safely. So is my experience to date.

The perfect solution would be the associative array at $TBE_STYLES['stylesheet']. Note the missing 2. I thought, it was clever to just extend this array to my needs like in the following code. Unfortunately, it didn´t work as expected.

$TBE_STYLES['stylesheet']['bbb_sortwizard'] = t3lib_extMgm::extRelPath($_EXTKEY).'myownway.css';

This would make every extension that needs a css file loaded to save it using the extension´s unique key. But, it did not work out. Two fields are predefined:

[modulemenu]=sysext/t3skin/stylesheets/modulemenu.css
[backend-style]=sysext/t3skin/stylesheets/backend-style.css

A good point to start on drilling the holes into the core, eh? ^^

Tonight, I rather used the quicker solution that will work in a way:

Putting the css inline

$TBE_STYLES['inDocStyles_TBEstyle'] .= '
.someclass {margin-top: 10px;}
.anotherclass {border: 1px solid black;}';

See the nasty concatenation of this value. It is naive to think that this is the best possible way to bring in own style to the backend of TYPO3. Well, the conclusion is, as long the internet does not present me more information on that issue (tell me how to do it in a constructive comment, this is appreciated) I will stick to the last mentioned way of inline css.

If you do as well, please concatenate too, that if you happen to be the last extension to be loaded, the code of the other extensions are respected, too. “Older” css commands otherwise would be deleted. Thank you.

similar posts @ bloxtacy:

6 thoughts on “$TBE_STYLES and custom css in TYPO3 backend

  1. Thank you for highlighting an annoyance in the TYPO3 backend.

    Did you try checking into any of the skin extensions and seeing how the TYPO3 3 backend is wiped away?

    I wonder if some JavaScript library includes in a similar matter are causing issues for another project.

    Good luck and keep us informed of what you find.

  2. Hi Michael, I´ve had my experience with the good looking t3skin_improved on 4.0.x and 4.1.x systems. but on 4.2 it seems to have no effect at all. the css file is included by this extension as follows:

    // moving styleSheetFile_post from t3skin to empty stylesheet2 (anyway inDocStyles_TBEstyle is not used)
    $TBE_STYLES['stylesheet2'] = $TBE_STYLES['styleSheetFile_post'];
    // replacing styleSheetFile_post
    $TBE_STYLES['styleSheetFile_post'] = $temp_eP.'stylesheets/stylesheet.css';

    Not what I wanted when I wrote it. The inline css style works for systems where I know that only my extension is adding css commands. More investigation soon.

  3. Pingback: Mes favoris du 25-01-10 au 26-01-10 » Gilles Toubiana

  4. Yes, that’s totally ugly.

    You can use the PageRenderer in 4.3 to add stylesheets (in your BE module). The doc-Classes (fullDoc etc.) hold a reference to the PageRenderer in a variable and so you can call $doc->pageRenderer->addStylesheet() (think the variable is called pageRenderer).

    We’re working on improved skinning capabilities. I had the same solution $TBE_STYLES['stylesheet']['bbb_sortwizard'] in mind. Do you think this is still needed, with the possibility to add them using the PageRenderer?

    Steffen

  5. Hi Steffen,
    the hint with the PageRenderer sounds great.

    The TBE_STYLES method may have it´s problems, so… i´ll stick to the PageRenderer, though i haven´t tried it yet.

    Thanks for your comment.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>