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

Sebastian Schreiber me at schreibersebastian.de
Tue Mar 29 11:28:24 CEST 2011


Am 29.03.2011 11:08, schrieb François Suter:
> Hi,
>
>> 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?
>
> Still no luck. I tried to load my JS file from within initializeView() 
> or initializeAction(), but no luck. As soon as there's an internal 
> redirection (in this case from "create" action to "new" action, 
> because there are validation errors), my JS file does not get loaded.
>
> Does anyone have an idea where I should place my loading call so that 
> it doesn't get lost upon redirection?
>
> Cheers
>
Hi,
i´m using special viewhelpers for that.
I think it is better instead of loading the js files within the controller.

The viewhelpers are very simple.
For example:

class Tx_SschFluidExtbaseHelper_ViewHelpers_Meta_AddFooterJsViewHelper 
extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper {

     /**
      * renders a special title for the page
      *
      * @param string $title
      * @return string $content: The pagebrowser
      */
     public function render($file = NULL) {

         if ($file === NULL) {
             $file = $this->renderChildren();
         }
         // Makes no sense to use the DPI here
         $pageRenderer = t3lib_div::makeInstance('t3lib_PageRenderer'); 
// it is a singleton, so we get always the same instance
         /* @var $pageRenderer t3lib_PageRenderer */
         $pageRenderer->addJsFooterFile($file);
     }
}


-- 
Sebastian Schreiber
(Medieninformatiker)
(TYPO3 Certified Integrator)

Sülzburgstraße 36
D-50937 Köln

T  0221 677 88 541
M  0176 431 05 790

Skype schreibersebastian.de

me at schreibersebastian.de
www.schreibersebastian.de

Steuernummer: 219 / 5302 / 2302



More information about the TYPO3-project-typo3v4mvc mailing list