【问题标题】:How to add a css class to an href in Silverstripe CMS editor?如何在 Silverstripe CMS 编辑器中将 CSS 类添加到 href?
【发布时间】:2015-10-29 20:24:25
【问题描述】:

如何在 silverstripe CMS 编辑器中将 Class 添加到 href 或任何其他 css 元素?

我在 editor.css 样式表中添加了一个自定义 css 类。

我希望链接看起来像这样:

<a href="http://www.example.com" class="my-custom-class">Click me</a>

我尝试这样做的方式最终得到了这个结果(例如,它在链接周围包裹了一个&lt;p&gt; 标签):

<p class="my-custom-class">
    <a href="http://www.example.com">Click me</a>
</p>

我知道您可以使用 CMS 编辑器中的 HTML 源代码编辑器手动添加类,但如果可以的话,我想尽量避免这样做。

【问题讨论】:

    标签: silverstripe


    【解决方案1】:

    正如jonom's great TinyTidy module 所见,您可以在您的 /mysite/_config.php 中尝试:

    $formats = array(
        // Links
    
        array(
            'title' => 'Links'
        ),
        array(
            'title' => 'Arrow',
            'attributes' => array('class'=>'arrow'),
            'selector' => 'a'
        ),
        array(
            'title' => 'Button',
            'attributes' => array('class'=>'button'),
            'selector' => 'a'
        ),
    );
    //Set the dropdown menu options
    HtmlEditorConfig::get('cms')->setOption('style_formats',$formats);
    

    【讨论】:

    • 谢谢!效果很好:)
    猜你喜欢
    • 1970-01-01
    • 2016-01-05
    • 1970-01-01
    • 1970-01-01
    • 2014-06-14
    • 1970-01-01
    • 2019-09-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多