简体   繁体   English

TYPO3 ckeditor 表 - 添加 div 响应 class

[英]TYPO3 ckeditor table - add div for responsive class

In the TYPO3 ckeditor is the default html output:在TYPO3 ckeditor中默认是html output:

<table class="table">
   ...
</table>

for the responsive bootstrap table i need a wrap around the Tag:对于响应式引导表,我需要围绕标签:

<div class="table-responsive">
  <table class="table">
    ...
  </table>
</div>

Bootstrap 5 responsive table: Bootstrap 5 响应表:
https://getbootstrap.com/docs/5.1/content/tables/#responsive-tables https://getbootstrap.com/docs/5.1/content/tables/#responsive-tables

How can i add a wrap?我怎样才能添加包装?

i add this "ckeditor externalPlugins" for table: https://github.com/benjaminkott/bootstrap_package/blob/master/Resources/Public/CKEditor/Plugins/Table/plugin.js我为表添加了这个“ckeditor externalPlugins”: https://github.com/benjaminkott/bootstrap_package/blob/master/Resources/Public/CKEditor/Plugins/Table/plugin.js

maybe i could add a wrap to the frontend there?也许我可以在那里的前端添加一个包装?

Make a config.yaml line:创建一个 config.yaml 行:

externalPlugins:
    table_wrapper: {resource: "EXT:my_ext/Resources/Public/JavaScript/Plugins/wrapper.js"}

With js:使用 js:

CKEDITOR.plugins.add('table_wrapper', { 
    init: function (editor) {
        editor.on('insertElement', function (event) {
            if (event.data.getName() === 'table') {
                var div = new CKEDITOR.dom.element('div').addClass('table-responsive'); // Create a new div element to use as a wrapper.
                event.data.appendTo(div); // Append the original element to the new wrapper.
                event.data = div; // Replace the original element with the wrapper.
            }
        }, null, null, 1);
    }
});

Also make sure the tags are allowed etc.还要确保允许使用标签等。

You can use TypoScript to add the necessary wrapper to the frontend:您可以使用 TypoScript 将必要的包装器添加到前端:

lib.parseFunc_RTE {
    externalBlocks {
        table {
            stdWrap {
                wrap = <div class="table-responsive">|</div>
            }
        }
}

This will then apply to all <table> HTML elements inside RTE fields.然后,这将应用于 RTE 字段内的所有<table> HTML 元素。

The Bootstrap Package works the same way: https://github.com/benjaminkott/bootstrap_package/blob/master/Configuration/TypoScript/ContentElement/Helper/ParseFunc.typoscript#L91 Bootstrap Package 的工作方式相同: https://github.com/benjaminkott/bootstrap_package/blob/master/Configuration/TypoScript/ContentElement/Helper/ParseFunc.typoscript#L91

thanks for the nice Solution!感谢您提供的解决方案!

but it dont work, i do this:但它不起作用,我这样做:

RTE Config: RTE 配置:

editor:
  externalPlugins:
    table_responsive: { resource: "EXT:rlp_base/Resources/Public/RTE/Plugins/Table.js" }
    table_wrap: {resource: "EXT:rlp_base/Resources/Public/RTE/Plugins/TableWrap.js"}

and this:和这个:

editor:
  ...
  config:
    ...
    extraPlugins:
      - justify
      - table_responsive
      - table_wrap

in the TableWrap.js is this:在 TableWrap.js 中是这样的:

'use strict';

(function() {

    CKEDITOR.plugins.add('table_wrap', {
        init: function (editor) {
            editor.on('insertElement', function (event) {
                if (event.data.getName() === 'table') {
                    var div = new CKEDITOR.dom.element('div').addClass('table-responsive'); // Create a new div element to use as a wrapper.
                    event.data.appendTo(div); // Append the original element to the new wrapper.
                    event.data = div; // Replace the original element with the wrapper.
                }
            }, null, null, 1);
        }
    });

})();

Example like this: https://github.com/benjaminkott/bootstrap_package/blob/master/Resources/Public/CKEditor/Plugins/Table/plugin.js像这样的例子: https://github.com/benjaminkott/bootstrap_package/blob/master/Resources/Public/CKEditor/Plugins/Table/plugin.js

my Frontend HTML output is this:我的前端 HTML output 是这样的:

<div class="ce-bodytext">
  <table class="table">
    <tbody><tr>
      ...
    </tr></tbody>
  </table>
</div>

Maybe it's another javascript error?也许这是另一个 javascript 错误?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM