silverstripe - 如何在 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);
解决方案
看起来您需要做的就是创建一个editor.css
文件,将您的样式放入其中,然后将以下代码段放入您的mysite/_config.php
文件中。
use SilverStripe\Forms\HTMLEditor\TinyMCEConfig;
TinyMCEConfig::get('cms')
->addButtonsToLine(1, 'styleselect')
->setOption('importcss_append', true);
样式会自动添加到下拉列表中。
推荐阅读
- r - 如何从数据框列表中删除列?
- python - 如何将 MyPy 将接受的类型提示作为参数传递给在内部定义函数的函数?
- c# - Android设备管理器系统镜像下载错误,Xamarin
- configuration - 我可以设置截止时间吗
- terraform - Is there any way to reference to old plan in terraform?
- javascript - Cypress:如何检查我的请求负载数据?
- r - 用一个函数生成不同的类向量
- javascript - 确保文件遵循样式指南
- java - JScrollPane 中 JTextPane 文本后面的静态图像
- javascript - 用数组 javascript 过滤掉数组