[TYPO3-mvc] Loading JS files in Extbase plugins: best practice?
Franz Koch
typo3.RemoveForMessage at elements-net.de
Tue Mar 29 11:36:54 CEST 2011
Hey,
> $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?
AFAIK there is no special Extbase implementation for dealing with
JSfiles, so your current way is fine. As Sebastian wrote you could also
use the response object and add some additionalHeaderData there, but
this won't respect your JS handling settings in TYPO3 (like move all JS
to bottom etc). So the pageRenderer should be fine.
> 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?
Please watch out for the correct terms in case of "redirect" and
"forward". If a validation error occurs Extbase should forward to the
new action and not redirect to it. A redirect would be a
header(location:...) redirect while a forward is only done internally
without creating a new request and is also passing the incoming
parameters to the forwarded action (unlike with redirects by default).
I think the issue in your case might be a USER/USER_INT one. I suppose
your "new" action might be cached while your "create" is uncached. I'm
not sure if TYPO3 is already able to manipulate the HTML header of
already cached pages with USER_INT plugins - only read about issues
there once.
--
kind regards,
Franz Koch
More information about the TYPO3-project-typo3v4mvc
mailing list