【问题标题】:Silverstripe 3: Add a custom block to HTMLEditorFieldSilverstripe 3:向 HTMLEditorField 添加自定义块
【发布时间】:2019-05-17 00:51:06
【问题描述】:

我想在 html 编辑器字段中添加创建“div”的选项。

如何在格式下拉列表中添加一个选项以创建具有特定类的 div?

我已经使用 editor.css 中的代码成功地将样式添加到样式下拉列表中

.responsive-table {
    overflow-x: scroll;
}

我正在使用 silverstripe 3,并希望能够将我自己的选项添加到格式下拉列表中以创建各种元素。

【问题讨论】:

    标签: silverstripe


    【解决方案1】:

    在 SilverStripe 3 中,我们可以通过将以下内容添加到 mysite/_config.php 来编辑 HTMLEditorField 中的样式下拉项:

    HtmlEditorConfig::get('cms')->setOption('style_formats', [
        [
            'title' => 'Responsive table',
            'attributes' => ['class' => 'responsive-table'],
            'selector' => 'div',
        ],
    ]);
    

    上面的代码将使HTMLEditorField 样式下拉列表中有一个项目,一个Responsive table 选项可以应用于div 元素。如果我们希望将其应用于table 元素,我们可以在selector 选项中进行更改。

    这是一个方便的模块,它展示了我们如何更改 SilverStripe 3 中的 HTMLEditorField 的示例: https://github.com/jonom/silverstripe-tinytidy/blob/master/_config.php

    【讨论】:

    • 我已经让它工作并创建了一个 div。但是,我也有一些自定义样式,我在 editor.css 中编辑,包括使用 HtmlEditorConfig::get('cms')->setOption('content_css', project() . '/css/editor.css'); 是否有可能在无需将旧样式也编码到 config.php 的情况下仍然可以使用?
    • 不幸的是,我认为这是其中之一。您可以通过上述setOption style_formats 方法或通过链接到editor.css 文件中的类的setOption content_css 方法设置样式下拉列表的所有选项。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-01
    相关资源
    最近更新 更多