Skip to content

Instantly share code, notes, and snippets.

@hphoeksma
Created June 6, 2012 19:07
Show Gist options
  • Save hphoeksma/28645ad6b1ac2e484425 to your computer and use it in GitHub Desktop.
Save hphoeksma/28645ad6b1ac2e484425 to your computer and use it in GitHub Desktop.
Add JS to your footer from within Extbase
$pageRenderer = $GLOBALS['TSFE']->getPageRenderer();
$pageRenderer->addJsFooterLibrary(
'jquerycycle',
t3lib_div::getFileAbsFileName('EXT:simply_slideshow/Resources/Public/JavaScript/jquery.cycle.all.js')
);
@hphoeksma
Copy link
Author

/**
 * 
 */
public function initializeAction() {
    $pageRenderer = $GLOBALS['TSFE']->getPageRenderer();
    $pageRenderer->addJsFooterLibrary(
        $this->extensionName,
        t3lib_div::getFileAbsFileName('EXT:simply_feuser_subscribe/Resources/Public/JavaScript/SimplyFeUserSubscribe.js')
    );
    parent::initializeAction();
}

@Jpsy
Copy link

Jpsy commented Dec 15, 2015

TYPO3 7.6:

/**
 * 
 */
public function initializeAction() {
    $uniqueBlockNamePrefix = $this->request->getControllerVendorName() .'_'. $this->request->getControllerExtensionKey() . '_';
    $pageRenderer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Page\PageRenderer::class);
    $pageRenderer->addJsFooterLibrary(
        $uniqueBlockNamePrefix.'myJsBlockName1',
        \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->request->getControllerExtensionKey()) . 'Resources/Public/js/test.js'
    );
    parent::initializeAction();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment