3

As a follow-up to: How do I override the default CKEditor configuration?

The issue

We have a custom email template that uses <html>, <head>, <body>. When using either the CKEditor main 'email body' editor, or the standard textarea when creating a custom header/footer, these tags are stripped out.

Is this a combination of CKEditor and CiviCRM both stripping out these tags separately?

I've tried...

I originally tried adding the CKEditor config option fullPage=true . This works, but automatically adds <html>, <head>, <body> to every CKEditor instance (cross-posted here) .

But then I spotted that the <html>, <head>, <body> tags are also stripped if used within header and footer templates, as described in this forum post. And these fields do not use CKEditor.

2
  • 1
    John - Would it be possible for you to clarify precisely why you need those tags included, as opposed to reworking your template? That would be really helpful. Aug 7, 2015 at 18:13
  • We've tried reworking it, but can't seem to get the template working correctly in all the browsers, applications and devices we need to without these tags being present.
    – John
    Aug 10, 2015 at 10:01

7 Answers 7

3

Not a good solution but what you can do is disable Advanced Content Filter (ACF) in ckeditor by editing the config.js file in the ckeditor folder like this:

config.allowedContent = true;

See documentation for more info.

What I do is extend the ACF like this:

config.extraAllowedContent = 'html;head;body;span;ul;li;table;td;style;*[id];*(*);*{*}';

[ ] // for attributes

{ } // for styles

( ) // for classes

That way you prevent ckeditor from striping html, body, head, id's or any element tag or even attributes that you need, but it won't add the default html->head->body by default (the behaviour with fullPage = true). The downside is that you will have to add the line on each CiviCRM upgrade, and i don't belive it will work with header/footer templates, I haven't tried it though.

6
  • Thanks @John, for me looks like the easiest solution until CiviCRM 4.7 is released, where is seems like (as Coleman says in the mentioned post) we will be able to configure those options as needed.
    – Andrei
    Aug 11, 2015 at 20:41
  • I'm no expert on this, but it looks like this solution might be a bit unsafe. I'm not sure that it takes into account this: docs.ckeditor.com/#!/guide/dev_disallowed_content, heading 'How to allow everything except...', which says that if ACF is turned off then disallowed content is turned off too. I tried the above with disallowed content including 'script' and scripts were not disabled. In contrast, the solution in the link I mentioned gives control over what is disallowed. But maybe I'm wrong! Feel free to put me right if I've missed something.
    – Andyg8
    Oct 13, 2016 at 20:44
  • @Andyg8 you are correct, turning off ACF will turn off also disallowed content, what I was trying to say is that you either turn off ACF entirely or you specify what tags are allowed extending the default ACF settings with extraAllowedContent, so you could add the script tag to extraAllowedContent while ACF is still on, makes sense?
    – Andrei
    Oct 14, 2016 at 9:04
  • Ahh, that makes total sense. Somehow I missed that you were talking about two alternative options, and I applied both bits of code. I've learnt a lot from this experience. Thanks!
    – Andyg8
    Oct 14, 2016 at 20:09
  • 1
    @commonpike this is the post civicrm.org/blog/colemanw/big-changes-to-wysiwyg-editing-in-47
    – Andrei
    Nov 21, 2017 at 9:54
2

Another option: Don't use those tags in your email.

If you actually need a <title> in your email, sure, this isn't for you.

For the majority of cases, it's unlikely those top-level tags actually are required elements in the email content or design.

By replacing them with regular block-level elements like <div>, and updating the CSS to reflect these changes, you may find this sort of workaround isn't necessary at all.

That can keep things much simpler.

1

Can you add your custom email template to Civicrm Administer/Communication/ Message Templates (Add Message Template)? Then you can edit/paste in your tags such as , in the HTML section ( assuming you would be able to send the mail from civicrm, I don't know your context)

4
  • Hi Lesley, the message template also strips out the html, head and body tags because we are using the CKEditor, as mentioned in the question. CiviCRM strips these tags out of the custom header/footer as well.
    – John
    Aug 10, 2015 at 8:03
  • I meant can you edit the Civi Templates without using CKEditor? Aug 10, 2015 at 18:26
  • Ah I see. This would be possible, but we want to keep the editing exprience as easy as possible for admins. Ideally they could just load up th template and edit what they need to in the WYSIWYG then send the email :] Thanks for the suggestion.
    – John
    Aug 11, 2015 at 15:36
  • @LesleyEvensen Been trying this. See related question (not about CKEDITOR specifically) civicrm.stackexchange.com/questions/4671/… Aug 12, 2015 at 16:17
1

Bit hacky, but you could try including the necessary text via a smarty include. Turn on smarty for mail templates, copy the content from your template into a .tpl file then put it in the templates directory (or in the templates folder in an extension). Then include in the visual editor with:

{include file=CRM/membership.tpl} (or as appropriate)

You'd need to edit this file manually, outside of Civi, but it should stop CKeditor messing about with the content.

(FYI we had odd problems with the presence/non-presence of the $ sign in smarty tags when we included files like this, but that was a few versions ago so that bug may have been fixed by now.)

1
  • Could be a workaround, but I don't think this would be a very easy process for our email editors to follow. Would be a shame to have to circumnavigate the built-in tools. Thanks for the suggestion though.
    – John
    Aug 10, 2015 at 8:04
1

Our temporary solution is to customise the crmUi.js file that defines the CKEditor configuration for the mailing HTML body. The patch file for this, if anyone's interested, can be found here: https://gist.github.com/JKingsnorth/d89fc355ee3d43d3adfc

1

There is a good, baked-in solution for this now. Thanks to work by Coleman:

You can add the fullPage = true setting to the CKEditor configuration just for CiviMail in:

Administer > Customize Data and Screens > Display Preferences > Configure CKEditor > CiviMail tab > Advanced options > Set fullPage = true as an option.

Source: https://github.com/civicrm/civicrm-core/pull/9419#issuecomment-261834710

0

We had the same problem on a multisite / Aegir system and after much work solved this.

Our solution is detailed here: Solved: Is this a bug - [civicrm.files] variable

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.