Jump to content

unable to add <i> tag in body field


mrkhan
 Share

Recommended Posts

Hello,

i am trying to add

<i class="fa fa-check-circle-o"></i>

tag in body field but this tag is getting cleared by CKEditor.

even in body field i have switch off the ACF and HTML purifier.

i also try to put bellow lines in EXTRA Allowed Content

<i>foo</i>
<i>
<i class="fa fa-check-circle-o"></i>

now when i put above code in HTML source and press OK the above code got deleted.

see attachment.

how to fix this?

Thanks

post-2916-0-77784400-1446912420_thumb.pn

Link to comment
Share on other sites

Hi,

If you want to allow 'class' like in your case <i class="fa fa-check-circle-o"></i>

then go to CK Editor settings for your field and find 'Extra Allowed content'

Setup => Fields => yourfield => Input => put use acf back to yes

then scroll down where you see Extra Allowed content and open it

Looking at the given examples linked to docs.ckeditor.com

it should be something like this:  i(fa fa-check-circle-o)

or simply this: i(*)
 

Link to comment
Share on other sites

Hi mrkhan,

Ok I was digging this for a while and now have it working :)

It didn't work for me also in the beginning because I was testing it for the body field but overlooked the file

config-body.js Please first read  \site\modules\InputfieldCKEditor\README.txt

So, if you want to add/edit your <i class="fa fa-check-circle-o"></i> in your ckeditor body field then you have to configure

the file config-body.js To make this work: open in your editor \site\modules\InputfieldCKEditor\config-body.js

and make sure at the bottom it looks like this:

CKEDITOR.editorConfig = function( config ) {
    // Define changes to default configuration here. For example:
    // config.uiColor = '#AADC6E';
       config.enterMode = 2;
       config.allowedContent = 'i[*]{*}(*)';
};

The line config.enterMode = 2; prevents your <i> tag from being wrapped in a <p> tag wich is default behaviour of ckeditor.

The line config.allowedContent = 'i[*]{*}(*)'; allows the <i> tag with wild cards for attributes, styles and classes.

I tested this with processwire version 2.6.1 with a body field and all is working.

Disclaimer:

Tags and classes should stay in css outside ckeditor but when dealing with a client who is already used

to edit with a few html tags, adding only a few of them would be ok. I don't see any security issues here.

Installing the Hanna code module makes all this obsolete and is recommended by many people here.

But for only allowing a single html tag I think the powerful hanna code module is a bit overkill here.

  • Like 3
Link to comment
Share on other sites

Hi mrkhan,

Ok I was digging this for a while and now have it working :)

It didn't work for me also in the beginning because I was testing it for the body field but overlooked the file

config-body.js Please first read  \site\modules\InputfieldCKEditor\README.txt

So, if you want to add/edit your <i class="fa fa-check-circle-o"></i> in your ckeditor body field then you have to configure

the file config-body.js To make this work: open in your editor \site\modules\InputfieldCKEditor\config-body.js

and make sure at the bottom it looks like this:

CKEDITOR.editorConfig = function( config ) {
    // Define changes to default configuration here. For example:
    // config.uiColor = '#AADC6E';
       config.enterMode = 2;
       config.allowedContent = 'i[*]{*}(*)';
};

The line config.enterMode = 2; prevents your <i> tag from being wrapped in a <p> tag wich is default behaviour of ckeditor.

The line config.allowedContent = 'i[*]{*}(*)'; allows the <i> tag with wild cards for attributes, styles and classes.

I tested this with processwire version 2.6.1 with a body field and all is working.

Disclaimer:

Tags and classes should stay in css outside ckeditor but when dealing with a client who is already used

to edit with a few html tags, adding only a few of them would be ok. I don't see any security issues here.

Installing the Hanna code module makes all this obsolete and is recommended by many people here.

But for only allowing a single html tag I think the powerful hanna code module is a bit overkill here.

Thanks for all your help.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...