Jump to content
anderson

CKEditor add extra H1 button?

Recommended Posts

Hi,

I'm new, in every aspect.  I want to boost CKEditor a little: add some extra button H1,H2,H3.  (So, one step less than clicking "format" dropdown.)

I've seen this thread: Customise CKEditor toolbar per role

So I tried creating a /site/ready.php , inside which:

$this->addHookBefore('Field(name=my_ckeditor_field)::getInputfield', function(HookEvent $event) {
    $field = $event->object;
    // Add extra buttons for superuser only
    if($this->user->isSuperuser()) $field->toolbar .= ', Table, TextColor, h3';
});

Apparently it's wrong, backend home page doesn't load any more, other backend pages have this text before header, and "h3" button doesn't show, and "table" and "textcolor", neither.

Maybe this is a dumb question? Please help.

Share this post


Link to post
Share on other sites
2 hours ago, Autofahrn said:

Does your ready.php start with


<?php namespace ProcessWire;

And to have the H buttons you'll need some more code (maybe plugin) which can be triggered from the toolbar reference.

Edit:

https://ckeditor.com/cke4/addon/formatbuttons

Thank you very much!

I'll try to learn about CKE addon.

Now I add 

<?php namespace ProcessWire;

but why "Table, TextColor" still don't show? Did I miss something else?

Share this post


Link to post
Share on other sites

I put format-button folder under \site\modules\InputfieldCKEditor\plugins\

then: 

Edit field:body > Input > CKEditor Settings > plugins,  I check "format-button", save. But still nothing happens.

Share this post


Link to post
Share on other sites

Is your CkEditor field indeed named "my_ckeditor_field"? If not, you'll need to edit your ready.php accordingly.

Share this post


Link to post
Share on other sites
11 hours ago, Autofahrn said:

Is your CkEditor field indeed named "my_ckeditor_field"? If not, you'll need to edit your ready.php accordingly.

Thank you, my bad. Now I see Table and Textcolor.

Share this post


Link to post
Share on other sites

 

15 hours ago, Autofahrn said:

And to have the H buttons you'll need some more code (maybe plugin) which can be triggered from the toolbar reference.

Now I got it, I have to add a line in CKEditor Toolbar, and must be lowercase. 

Share this post


Link to post
Share on other sites

Glad you get it running. In the end its not that complicated, but the dependancies need to be understood first. I know....

And, yes, toolbar entries are case sensitive (no need for an additional line, you may place the buttons anywhere), and sometimes you'll need to read the code in plugin.js to find the string you have to put in.

Share this post


Link to post
Share on other sites
15 hours ago, Autofahrn said:

Glad you get it running. In the end its not that complicated, but the dependancies need to be understood first. I know....

And, yes, toolbar entries are case sensitive (no need for an additional line, you may place the buttons anywhere), and sometimes you'll need to read the code in plugin.js to find the string you have to put in.

Thanks again, I appreciate it!

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...