如何在后端添加css和JS

如何在后端添加css和JS

本文介绍了TYPO3:如何在后端添加css和JS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在后端添加 css javascript 文件?

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.

系统:TYPO3 v9

模式:作曲家模式

目标:自定义内容元素

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

推荐答案

在TYPO3 v9中,您必须执行以下操作并且在每种模式下

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

CSS

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

此处的路径(CSS)是一个目录,因此它将读取指向目录中的所有文件。

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\PageRender
$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, '');

参数:

addJsFile(
       $file,
       $type = 'text/javascript'
       $compress = 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.

其他信息:

如果你想使用TYPO3的jQuery(强烈推荐它以避免冲突)你也应该使用以下内容:

If you want to use TYPO3's jQuery (strongly recommended 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\PageRender
   ...
}

这篇关于TYPO3:如何在后端添加css和JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 05:41