[TYPO3-dev] Creating a common hook plugin

Tapio Markula tapio.markula at dnainternet.net
Sun Aug 27 20:24:53 CEST 2006


JoH kirjoitti:
>> What could be reasonable is to create a common hook plugin for
>> some core files
>>
>> template.php - that file is really core and
>> it would be nice to create hooks for CSS and JavaScript
>> in order to add with user-defined class methods (functions) CSS and
>> JavaScript
>> to the HEAD section of page
> 
> What is wrong with
> 
> $this->doc = t3lib_div::makeInstance('bigDoc');
> $this->doc->JScode = '
> <link rel="stylesheet" type="text/css" href="whatever.css" />
> <script type="text/javascript" src="whatever.js"></script>
> ';
> ?
> 
> Don't see the reason for a hook there.
> 
> Joey


JavaScript is not normally needed for *all* pages of the BE.
That would be satisfactory solution in many cases.

Adding JavaScript, which is needed by just some files,
is commonly incorrect way adding JavaScript
directly to the function
function startPage() making XCLASS for template.php


But there might be JavaScript, which is needed almost for every page.
That kind of JavaScript would be reasonable to set using a hook
for function startPage().

For example if you would like to replace every textarea, which is not
RTE with our own version of textarea.
You *can't* know in which page to use it.
You don't know page, where you could add
$this->doc = t3lib_div::makeInstance('bigDoc');
etc.
That solution is completely unsatisfactory.

If you don't have JavaScript related hook for function startPage(),
you *must* create XCLASS for template.php

Peter Klein made pmktextarea - that needs XCLASS for template.php
in order to add for *undefined pages* certain JavaScript.



 > $this->doc = t3lib_div::makeInstance('bigDoc');
 > $this->doc->JScode = '
 > <link rel="stylesheet" type="text/css" href="whatever.css" />
 > <script type="text/javascript" src="whatever.js"></script>
 > ';

could not work because you can't beforehand know for which pages to add it.

The most reasonable way to solve this kinds of need of very generic
JavaScript is hook for adding very generic JavaScript.

It is bad to force making XCLASS class.ux_template.php
creating that.

Well that kind of very generic JavaScript has been needed seldom.


Anyway hook for CSS for template.php is really needed and
need is more obvious.

Conditinal CSS might be needed for every - or almost every - core file 
in BE.
For example if you would like to add page tree based CSS for the BE
using TS Config for pages. Conditional CSS should be
for every page, which can relate with certain page.



templa.php handle CSS in function docStyles()
It is not enough to handle CSS using page level
$this->doc->inDocStylesArray[]
Condition for $this->doc->inDocStylesArray[]
should be possible to hande for the entire BE
with any kind of conditions.




More information about the TYPO3-dev mailing list