【问题标题】:How to add a css style to an element in the HTMLEditorField content editor in Silverstripe 4?如何在 Silverstripe 4 的 HTMLEditorField 内容编辑器中为元素添加 css 样式?
【发布时间】:2018-06-21 22:46:04
【问题描述】:

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

我们如何在 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);

【问题讨论】:

    标签: silverstripe silverstripe-4


    【解决方案1】:

    看起来您需要做的就是创建一个editor.css 文件,将您的样式放入其中,然后将以下sn-p 放入您的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

    【讨论】:

      猜你喜欢
      • 2011-01-09
      • 1970-01-01
      • 2010-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多