CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • CiviMail css - convert to inline
Pages: [1]

Author Topic: CiviMail css - convert to inline  (Read 2621 times)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
CiviMail css - convert to inline
November 21, 2013, 06:10:55 pm
Hi,

We have been working with a simple token to embed a view into a civimail https://github.com/eileenmcnaughton/civicrm_views_token (in this case the customer uses nodequeue to group a selection of articles for the newsletter although I can think of other use cases).

However, the issue is the styling. We can add style tags to the header & this gives us a nicely formatted email ..... unless people are using gmail - which removes them & requires them to be in the html elements. I understand there are modules / libraries out that that will process html & 'in-line' style elements - has anyone investigated at all.

NB - adding the style to the view seems like a drag
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: CiviMail css - convert to inline
November 22, 2013, 12:20:21 am
more complete
https://github.com/christiaan/InlineStyle
seems to be easier
https://github.com/djfm/cssin

Both seems to be easy to use, and probably both choke on weird css problems here and there, choose your poison ;)

Seriously, would be awesome and avoid a lot of complains about formating gone bad

-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: CiviMail css - convert to inline
December 04, 2013, 02:35:58 pm
OK so we tried the first of these & found it worked with this patch

https://github.com/eileenmcnaughton/civicrm-core/commit/116dfd92348d2e08b0149bac0d0283c7f3353b23

and adding the file to packages

https://github.com/eileenmcnaughton/civicrm-packages/commit/972b1b02ee0af41b61aa71678aece422235f7832

What that means is that links to stylesheets with the the html are converted into inline html - which is quite powerful actually.

In conjunction with https://github.com/eileenmcnaughton/civicrm_views_token this really does open up the possibility of 'no-touch newsletters' - ie. a fully-formatted list of latest / most popular news items, a view of upcoming events. A weekly security advisory  or whatever - it addresses the issue of having to both put content on your website AND in your newsletter.

So, what are the technical issues

1) testing - any issues with this will almost certainly happen on edge cases  - so it's very hard to test thoroughly. This is substantially mitigated by the fact there is no change at all unless there is a css link (e.g. <link rel="stylesheet" type="text/css" href="http://civicrm.org/civicrm.css">

2) performance - at the moment we have it parsing once per mail - there is a case for that given it's not impossible that a token could provisionally add a stylesheet - however, if we assumed the stylesheets would always be the same we could return early if none are found in the first one. We probably need a 'big sender' to test to see if performance issues exist when there are stylesheets present

3) deployment - if the in-lining is accepted for core but not until 4.5 then we have to figure out how to deliver it for the drupal views token prior to then - I don't fancy packaging the 'late-parser' approach in the above patch as an extension. We could do the parsing in the drupal_views_token module & process only the portion added by the token - but then we have to consider what happens with 4.5 if the late parser is included - we wouldn't want it to be processed twice (for performance & possibly output reasons).

I will probably wait to see what sponsorship there is before trying to look at a deployment approach that would make this more generally available.

4) note that sending a test email from civimail doesn't seem to process token hooks

5) I also thought it should be possible to configure a header with only html since the html message is parsed to text at the end but the field is compulsory. I'm not sure if this rules out adding the views token (which returns html) in the header element - I would need to do more testing as to what happens to the text version
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Owen

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 2
    • Leukaemia & Lymphoma Research
  • CiviCRM version: 4.3.4
  • CMS version: Drupal 7
  • MySQL version: -
  • PHP version: -
Re: CiviMail css - convert to inline
December 05, 2013, 12:46:44 am
Hey Eileen

At what point does the inlining happen?
Will the editor of an email see the CSS inlined when writing the email?
If there is already inline CSS will this overwrite it?

We're doing some Civimail interface bits at the moment.

O.

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: CiviMail css - convert to inline
December 05, 2013, 12:06:33 pm
I've added it to the 'compose' function - and, importantly, it is after the token replacement - what I found is

1) Wysiwig editor - inline stylesheets work in the editor - but if you have them in your header rather than your template you may not get the benefit of them (unchanged / need to confirm as I think headers may be visible)
2) preview editor - yes, with this patch inline stylesheets are applied in the preview editor (header or otherwise)
3) test email - doesn't swap out the hook token & I don't think it does the inlining either
4) Civimail emails - yes - styles converted to inline html styles gmail & other email clients

Re existing inline css - I have done limited testing of that - you might want to give a test. The patch is very small & easy to apply

Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: CiviMail css - convert to inline
February 24, 2014, 12:41:38 pm
Note the above commit has disappeared - here is the patch that goes in core

diff --git a/CRM/Mailing/BAO/Mailing.php b/CRM/Mailing/BAO/Mailing.php
index c9571bf..eb824ed 100644
--- a/CRM/Mailing/BAO/Mailing.php
+++ b/CRM/Mailing/BAO/Mailing.php
@@ -1202,7 +1202,7 @@
       if ($useSmarty) {
         $htmlBody = $smarty->fetch("string:$htmlBody");
       }
-      $mailParams['html'] = $htmlBody;
+      $mailParams['html'] = self::inlinecss($htmlBody);
     }
 
     if (empty($mailParams['text']) && empty($mailParams['html'])) {

It may make more sense to do this as a hook - perhaps the 'alterMailParams' hook will work - I'd need to try
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: CiviMail css - convert to inline
March 11, 2014, 04:46:20 pm
We have now moved this to an extension

https://github.com/eileenmcnaughton/nz.co.fuzion.cssinline
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: CiviMail css - convert to inline
August 31, 2016, 03:44:38 pm
Hi Eileen,
I just found your nifty css inline extension and am pretty excited to see this. As @xavier notes, "Writing html email is a PITA."  ;D

Anyway, I just thought I'd drop by and say thanks. I haven't tried it yet but am in the midst of installing and testing now.

Cheers,
Andrew
My CiviCRM Extension Workshop: https://github.com/awasson

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: CiviMail css - convert to inline
August 31, 2016, 04:30:40 pm
Regarding this extension, I have a question.

If I install the extension, I see it is bundled with cssin already installed in the packages directory. When I create a newsletter template I insert a link to my stylesheet:

<link href="http://mysite.org/sites/all/themes/mytheme/css/newsletter.css?ver=3.0" rel="stylesheet" type="text/css" />

My stylesheet lives at: /sites/all/themes/mytheme/css/newsletter.css

How do I tell the WYSIWYG tool that the styles I have defined in my stylesheet exist? Is there a config page somewhere for the WYSIWYG that I don't know about?

Thanks,
Andrew
My CiviCRM Extension Workshop: https://github.com/awasson

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: CiviMail css - convert to inline
August 31, 2016, 07:05:35 pm
I think it just gets the stylesheet from your header & wgets it (if it can)
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: CiviMail css - convert to inline
August 31, 2016, 10:04:18 pm
Thanks Eileen,

I must be doing something wrong then... It doesn't seem to be doing that.

This is a D7 site running CiviCRM 4.6.20 LTS

I've installed the extension and as far as I can tell it installed correctly. cssin is bundled with the extension so I haven't downloaded it or anything.

I've got a very simple stylesheet called at: /sites/all/themes/mytheme/css/newsletter.css It jus has a couple of styles defined as follows:

Code: [Select]
.copy {
  font-family: helvetica, arial, sans-serif;
  font-size: 1em;
}

.copy-large {
  font-family: helvetica, arial, sans-serif;
  font-size: 1.5em;
}


I've got a simple email template that contains nothing except for:
<link href="http://mysite.org/sites/all/themes/mytheme/css/newsletter.css?ver=3.0" rel="stylesheet" type="text/css" />

The link is supposed to go in the EMail template, Administer -> CiviMail -> Message Templates, correct?

I've cleared cache's and that hasn't made a difference.

By the way, I see that the CKEditor in CiviCRM has a file called styles.js that tells it what styles it can use.
My CiviCRM Extension Workshop: https://github.com/awasson

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • CiviMail css - convert to inline

This forum was archived on 2017-11-26.