最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - TYPO3: How to add a css and JS on the backend - Stack Overflow

programmeradmin0浏览0评论

How do i add css and javascript file(s) on the backend?

I would like to use those files for custom created content elements in order to make them more appealing for the user.

System: TYPO3 v9
Mode: Composer Mode
Target: Custom Content element

How do i add css and javascript file(s) on the backend?

I would like to use those files for custom created content elements in order to make them more appealing for the user.

System: TYPO3 v9
Mode: Composer Mode
Target: Custom Content element

Share edited May 3, 2019 at 12:41 Aristeidis Karavas asked May 3, 2019 at 12:24 Aristeidis KaravasAristeidis Karavas 1,95614 silver badges34 bronze badges 2
  • Possible duplicate of How to include a custom CSS file in TYPO3 – user5734311 Commented May 3, 2019 at 12:26
  • 3 @chris G not even close to duplicate. read the content again carefully – Aristeidis Karavas Commented May 3, 2019 at 12:28
Add a ment  | 

1 Answer 1

Reset to default 9

In TYPO3 v9 you will have to do the following and on every mode

CSS

$GLOBALS['TBE_STYLES']['skins']['your_extension_key'] = array();
$GLOBALS['TBE_STYLES']['skins']['your_extension_key']['name'] = 'My Awesome Name';
$GLOBALS['TBE_STYLES']['skins']['your_extension_key']['stylesheetDirectories'] = array(
    'visual' => 'EXT:yourextension/Resources/Public/Css/Backend',
    'theme' => 'EXT:yourextension/Resources/Public/Css/Monokai'
);

The path here (CSS) is a directory, so it will read all the files in the pointed directory.

JS

$renderer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Page\PageRenderer::class);
$renderer->addJsFile('yourextension/Resources/Public/JavaScript/Backend.js', 'text/javascript', false, false, '', true,  '|', false, '');
$renderer->addJsFile('yourextension/Resources/Public/JavaScript/another.js', 'text/javascript', false, false,  '', false, '|', false, '');

Parameters:

addJsFile(
       $file, 
       $type = 'text/javascript'
       $press = true,
       $forceOnTop = false,
       $allWrap = '',
       $excludeFromConcatenation = false,
       $splitChar = '|',
       $async = false,
       $integrity = ''
);

In large files, it might have some problems with the loading, but if anyone could confirm that, i would really appreciate it.

Additional information:

If you want to use TYPO3's jQuery (strongly remended it in order to avoid conflicts) you should use the following as well:

require(["jquery"], function($) {
   //your awesome function
});

You could use a condition as well to make sure that it is loaded on the backend:

if (TYPO3_MODE === 'BE') {
   $renderer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Page\PageRenderer::class);
   ...
}
发布评论

评论列表(0)

  1. 暂无评论