[TYPO3-mvc] How to use jQuery in BE Module?

Stig Nørgaard Færch snf at dkm.dk
Fri Feb 10 10:52:04 CET 2012


Den 09-02-2012 16:12, Sebastian Schreiber skrev:
> Write a viewHelper like the following one:

Thanks both for the suggestions. I went for this solution.

I made a couple of changes - might be useful for others.
Now it will add both css and js files:

class Tx_MyExt_ViewHelpers_Be_AddFileRelativeToExtensionViewHelper 
extends Tx_Fluid_ViewHelpers_Be_AbstractBackendViewHelper {

     /**
      *
      * @param string $extensionKey
      * @param string $pathToJsFile
      * @return void
      */
     public function render($fileType = NULL, $pathToFile = NULL) {
         if (NULL === $pathToFile) {
             $pathToJsFile = $this->renderChildren();
         }
             //if fileType is not defined, find it by file extension
         if (NULL === $fileType) {
             $fileType = substr(strrchr($pathToFile,'.'), 1);
         }
         $pageRenderer = $this->getDocInstance()->getPageRenderer();
             /* @var $pageRenderer t3lib_PageRenderer */
         if($fileType == 'js') {
             $pageRenderer->addJsFile($pathToFile);
         } else if($fileType = 'css') {
             $pageRenderer->addCssFile($pathToFile);
         }
     }
}

In the template:
<Tx_MyExt_ViewHelpers:be.addfilerelativetoextension 
pathToFile="{f:uri.resource(path:'scripts/main.js')}" />

/Stig


More information about the TYPO3-project-typo3v4mvc mailing list