首页 > 解决方案 > 如何在 Silverstripe 4 的 HTMLEditorField 内容编辑器中为元素添加 css 样式?

问题描述

在 SS 3.x 中,我们可以使用以下代码通过下拉菜单将自定义元素添加到HTMLEditorField内容编辑器中。Styles我的主要用途是将标准链接转换为样式按钮链接。

我们如何在 SS 4.x 中实现这一点?

这就是它在 3.x 中的完成方式

_config.php

<?php
$formats = array(
    array(
        'title' => 'Buttons'
    ),
    array(
        'title' => 'Custom Button',
        'attributes' => array('class'=>'custom-btn'),
        'selector' => 'a'
    )
);
//Set the dropdown menu options
HtmlEditorConfig::get('cms')->setOption('style_formats',$formats);

标签: silverstripesilverstripe-4

解决方案


看起来您需要做的就是创建一个editor.css文件,将您的样式放入其中,然后将以下代码段放入您的mysite/_config.php文件中。

use SilverStripe\Forms\HTMLEditor\TinyMCEConfig;

TinyMCEConfig::get('cms')
    ->addButtonsToLine(1, 'styleselect')
    ->setOption('importcss_append', true);

样式会自动添加到下拉列表中。

参考:https ://docs.silverstripe.org/en/4/developer_guides/customising_the_admin_interface/typography/#custom-style-dropdown


推荐阅读