[TYPO3-mvc] Loading JS files in Extbase plugins: best practice?

François Suter fsu-lists at cobweb.ch
Tue Mar 29 09:14:10 CEST 2011


Hi all,

I'm wondering about best practices for loading JavaScript files from 
within an Extbase plugin.

First of all, the general way of doing it. I'm using the following:

$pageRenderer = $GLOBALS['TSFE']->getPageRenderer();
$pageRenderer->addJsFile('some/path/Resources/Public/JavaScript/Application.js');

Is that the correct way to do it in Extbase or are there some specific 
methods?

Next question: I need to load this JS file only for some actions, not 
for all them. For example, I placed my code in the newAction() method. 
This works fine. But when I submit the data and have one or more 
validation errors, the create action redirects to the new action. And in 
this case, my JS file is not loaded. I'm assuming that it's being called 
too late and thus the JS file is not loaded, but I'm not sure. In such a 
case where would be the right place to call up the loading of the JS file?

Cheers

-- 

Francois Suter
Cobweb Development Sarl - http://www.cobweb.ch


More information about the TYPO3-project-typo3v4mvc mailing list