TYPO3 CKE编辑器允许数据属性

时间:2020-03-15 18:13:57

标签: ckeditor typo3 typo3-9.x

我添加了

- { name: "Data Test", element: "p", attributes: { 'data-test': "test" } }

到我的Yaml配置。我可以在编辑器代码中选择数据属性(并查看正确)。但是在保存内容之后,TYPO3还将从代码中删除data-tesst =“ test”。

我该如何解决? 感谢帮助! 马丁

buttons:
  link:
    relAttribute:
      enabled: true
    targetSelector:
      disabled: false
    properties:
      class:
        allowedClasses: 'button, button_hell'
      title:
        readOnly: false

imports:
- { resource: "EXT:rte_ckeditor/Configuration/RTE/Processing.yaml" }
- { resource: "EXT:rte_ckeditor/Configuration/RTE/Editor/Base.yaml" }
- { resource: "EXT:rte_ckeditor/Configuration/RTE/Editor/Plugins.yaml" }


editor:
  config:
    # css definitions for the editor
    contentsCss: "EXT:mw_theme/Resources/Public/Css/rte.css"
    # can be "default", but a custom stylesSet can be defined here, which fits TYPO3 best
    format_tags: "p;h1;h2;h3;h4;h5;h6;pre;address"

    stylesSet:
      # custom block level style
      - { name: "Button", element: "a", attributes: { 'class': "button" } }
      - { name: "Test", element: "p", attributes: { 'data-test': "test" } }

    toolbar:
      - [ 'Format', 'Styles' ]
      - [ 'Bold', 'Italic', 'Underline', 'Blockquote', 'Subscript', 'Superscript']
      - [ 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', 'HorizontalRule' ]
      - [ 'NumberedList', 'BulletedList']
      - [ 'Link', 'Unlink', 'Anchor', 'Table', 'SpecialChar', 'CodeSnippet', 'Youtube' ]
      - [ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord' ]
      - [ 'Undo', 'Redo', 'RemoveFormat', 'ShowBlocks' ]
      - [ 'Source', 'Maximize', 'About']
    removePlugins:
      - image
    extraPlugins:
      - justify
    justifyClasses:
      - text-left
      - text-center
      - text-right
      - text-justify
Allow tags
processing:
  allowTags:
    - dl
    - dt
    - dd

第ts页:

RTE { default { preset = mw_theme } }`

3 个答案:

答案 0 :(得分:0)

这取决于很多因素和您的其他配置,但您似乎确实如此。一种很常见的可行方法是将extraAllowedContent定义为Yaml中的其他配置设置,例如:

editor:
  config:
    extraAllowedContent: '*(*)[data-*]'

或者如果我理解另一行,也允许dt / dd / dl:

editor:
  config:
    extraAllowedContent:
      - '*(*)[data-*]'
      - dd
      - dl
      - dt

如果是后者,可能EXT:rte_ckeditor_dl值得一看,以便获得创建该列表的按钮。

答案 1 :(得分:0)

我找到了解决方法:

    extraAllowedContent:
  p[data-test];

答案 2 :(得分:0)

要允许将数据属性从RTE字段保存到db,您需要确保:

1)RTE(CKEditor)不会剥离属性。这可以使用extraAllowedContent进行配置。下面是一个示例,该示例如何在允许数据属性和类的默认规则之外另外允许id属性。

editor:
  config:
    extraAllowedContent:
      - "*(*)[data-*]"
      - "*[id]"

如果只需要添加数据属性,则不需要上面的配置,并且可以中继默认配置(来自rte_ckeditor / Configuration / RTE / Editor / Base.yaml),因为默认情况下,数据属性是允许的。

要测试此配置部分,请转至RTE,单击“查看源代码”按钮,然后切换回并再次切换,以查看属性是否消失。 如果仍然存在,则意味着您的RTE配置允许它。

2)然后,您需要配置PHP方面的内容-数据转换发生在将数据保存到db之前。请参见手册章节:https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Rte/Transformations/Process.html#transformations-process

下面是一个示例(摘自RTE yaml预设),允许在转换中使用data-abc属性(除了默认情况下允许的属性)。

processing:
  allowAttributes: [class, id, title, dir, lang, xml:lang, itemscope, itemtype, itemprop, data-abc]

因此,在您的情况下,您缺少转换部分上的正确配置。