TYPO3:如何向 RTE 添加元素,允许用户使用定义的 CSS 类

发布于 2024-12-25 12:54:55 字数 734 浏览 2 评论 0原文

我希望用户能够在 RTE 中选择文本样式,例如“详细信息”、“重要信息”、“人员姓名”等。所以我想定义一个 CSS 并且这个选项应该在 RTE 中显示。 CSS 样式应该是 span 并且仅设置颜色。

目前我有以下代码:

RTE.classes{
  highlight{
      name = test
      value = color:#0A8AD2;
  } 
}

RTE.default{
  ignoreMainStyleOverride = 1 
  useCSS = 1
  contentCSS = fileadmin/templates/css/rte_formats.css
  classesCharacter := addToList(highlight)
  classesParagraph := addToList(highlight)
  proc.allowedClasses := addToList(highlight)
}

CSS 文件的内容是

span.highlight, p.highlight {
    color:#0A8AD2;
}

但新添加的样式未显示在下拉列表中(textstyle)。我还在 rtehtmlarea 配置中启用了“附加内联元素”。我还尝试设置 showTagFreeClasses 等,但没有成功。然后我读到了缓存问题。我删除了 RTE 缓存以及浏览器缓存。还是没有结果。有什么问题吗?

I want that the user should be able to select an textstyle in RTE like Detail, Important, Name of person and so on. So I would like to define a CSS and this option should be shown in RTE. The CSS style should be a span and only setting a color.

Currently I have the following code:

RTE.classes{
  highlight{
      name = test
      value = color:#0A8AD2;
  } 
}

RTE.default{
  ignoreMainStyleOverride = 1 
  useCSS = 1
  contentCSS = fileadmin/templates/css/rte_formats.css
  classesCharacter := addToList(highlight)
  classesParagraph := addToList(highlight)
  proc.allowedClasses := addToList(highlight)
}

The content of the CSS file is

span.highlight, p.highlight {
    color:#0A8AD2;
}

But the new added style isn't shown in the drop down (textstyle). I also enabled "additonal inline elements" in th rtehtmlarea configuration. I also tried to set showTagFreeClasses and so on without success. Then I read about caching problems. I deleted the RTE cache as well as the browser cache. Still no result. What can be wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

完美的未来在梦里 2025-01-01 12:54:55

你基本上走在正确的轨道上!

我在使用 inlineStyle 时遇到了很多问题。其中之一是您必须显式取消定义 contentCSS 才能使内联工作(仅设置 ignoreMainStyleOverride = 0 是不够的!):

RTE.default.contentCSS >

我个人更喜欢专用的外部 CSS文件。需要了解的重要一点是,TYPO3 RTE 确实会解析此 CSS 文件,并且仅提供实际在其中找到的那些类!
因此,您必须使用 contentCSS 参数来定义 CSS,并且该 CSS 必须确实包含您希望向用户提供的类。下面是您必须如何定义它:

# TS-Config
RTE.default.ignoreMainStyleOverride = 1
RTE.default.contentCSS = fileadmin/templates/css/rte_formats.css

CSS 文件必须存在在给定的 URL 处,并且它必须包含您想要提供的 CSS 类的定义(如CSS 文件确实已解析,缺少的类不会显示在下拉选择器中):

/* content of rte_formats.css */
/* span. needed for RTE.default.classesCharacter */
/* p.    needed for RTE.default.classesParagraph */
span.highlight, p.highlight{ color:#0A8AD2; }

还有一个提示:
我建议不要用您自己的类名覆盖 allowedClasses,而是附加到它们:

RTE.default.proc.allowedClasses := addToList( highlight, myOtherClass, myThirdClass )

祝你好运!

You are basically on the right track!

I have experienced quite some problems using inlineStyle. One of them being that you have to explicitly undefine the contentCSS to make the inlines work (only setting ignoreMainStyleOverride = 0 is not enought!):

RTE.default.contentCSS >

I personally prefer a dedicated external CSS file. The important thing to know is that the TYPO3 RTE really parses this CSS file and only offers those classes that are actually found in there!
So you have to use the contentCSS parameter to define a CSS and this CSS must really contain the classes that you want to make available to the user. Here is how you must define it:

# TS-Config
RTE.default.ignoreMainStyleOverride = 1
RTE.default.contentCSS = fileadmin/templates/css/rte_formats.css

The CSS file must exist at the give URL and it must contain a definition for the CSS class that you want to provide (as said the CSS file is really parsed and missing classes will not show up in the dropdown selector):

/* content of rte_formats.css */
/* span. needed for RTE.default.classesCharacter */
/* p.    needed for RTE.default.classesParagraph */
span.highlight, p.highlight{ color:#0A8AD2; }

And one more hint:
I recommend not to overwrite the allowedClasses with your own class name(s), but append to them:

RTE.default.proc.allowedClasses := addToList( highlight, myOtherClass, myThirdClass )

Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文