4

How do you add a Class to an href or any other css element in the silverstripe CMS editor?

I have added a custom css Class in the editor.css stylesheet.

I want the link to look like this one:

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

The way that I have tried to do it ends up with this result (e.g it wraps a <p> tag around the link):

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

I realise you can use the HTML source code editor within the CMS editor to manually add in the class but want to try and avoid doing that if I can.

Korpel
  • 2,432
  • 20
  • 30
ifusion
  • 2,163
  • 6
  • 24
  • 44

1 Answers1

2

As seen at jonom's great TinyTidy module you might try in your /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);
wmk
  • 4,598
  • 1
  • 20
  • 37