RPJain
RPJain

Reputation: 27

How can we add javascript file to the front-end of typo3 from extensions

I just wanna add my javascript file to be added while rendering the all front-end pages not the back-end pages. I have tried :

if (TYPO3_MODE=="FE" )   {
   $pageRenderer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Page\PageRenderer::class);
   $pageRenderer->loadRequireJsModule('EXT:eyebase/Resources/Public/JavaScript/testinjectEyebaseJS.js','code');
}

but this code added my js file within the CDATA like:-

<script type="text/javascript">
/*<![CDATA[*/
/*RequireJS-Module-EXT:eyebase/Resources/Public/JavaScript/testinjectEyebaseJS.jse6fb06210fafc02fd7479ddbed2d042cc3a5155e*/
require(["EXT:eyebase/Resources/Public/JavaScript/testinjectEyebaseJS.js"], code);

/*]]>*/
</script>

Please guide me how to do this. Thanks in advance.

Upvotes: 1

Views: 4914

Answers (2)

Jonas Eberle
Jonas Eberle

Reputation: 2921

You would put this into TypoScript ("setup" part):

page {
  includeJS {
    testinjectEyebaseJS = EXT:eyebase/Resources/Public/JavaScript/testinjectEyebaseJS.js
  }
}

Have a look for the options here https://docs.typo3.org/m/typo3/reference-typoscript/master/en-us/Setup/Page/Index.html#includejs-array.

Upvotes: 0

Related Questions