1

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.

David
  • 5,882
  • 3
  • 33
  • 44
RPJain
  • 27
  • 1
  • 4
  • what is the problem to make it by `TypoScript`? Why you want to do it by PHP? – David Nov 15 '19 at 16:25
  • RequireJS is usually used in the backend only. You can use it in the frontend too but setup is completely up to you then without any standards by TYPO3. – David Nov 15 '19 at 16:28

2 Answers2

2

You can add CSS/JS via HeaderAssets and FooterAssets sections in your Fluid template.

See TYPO3: How could I add css and js files via controller initialize action and page renderer?

Julian Hofmann
  • 2,081
  • 1
  • 8
  • 16
0

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.

Jonas Eberle
  • 2,835
  • 1
  • 15
  • 25
  • Thanks For your reply Jonas , But my extension is for Backend and I tried to Make all the required files for TypoScript but It didn't worked . I followed the following file structure:- site_package/Configuration/TCA/Overrides/sys_template.php site_package/Configuration/TypoScript/constants.typoscript site_package/Configuration/TypoScript/setup.typoscript But it doesn't load my js file for frontend because Bootstrap_Package extension is used for FE. I want to add Js file for all FE pages from my custom extension. I hope You understood my issue. Please guide me and Thanks in advance. – RPJain Nov 16 '19 at 09:10
  • It will work even with bootstrap_package. Obviously your TypoScript is not loaded. Did you include it on your root page? (Template -> Edit -> Includes in the backend) – Jonas Eberle Nov 19 '19 at 10:21