代码之家  ›  专栏  ›  技术社区  ›  ifusion

如何在SilverStripe4的htmleditorfield内容编辑器中向元素添加CSS样式?

  •  2
  • ifusion  · 技术社区  · 7 年前

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

    我们如何在SS4.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);
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   Gavin Bruce    7 年前

    看起来你需要做的只是创建一个 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

    推荐文章