I'm really quite pleased with the Simplenews module together with Mime Mail and CSS compressor modules, they get the job done nicely.
However I'm having problems when I'm trying to customize certain elements by adding inline styles - they simply get removed. It seems the CSS compressor is stripping all the existing inline styles and replacing them with what is set in mail.css.
I'm using the following template files to custom my newsletter (content type) layout:
simplenews-newsletter-body.tpl.php
simplenews-newsletter-footer.tpl.php
I place all of the styles in mail.css, however for some elements there is the need to put some custom inline styles directly in the template files mentioned above.
Can anyone else confirm this or am I missing something?
| Comment | File | Size | Author |
|---|---|---|---|
| #20 | emogrifier-inline-style-precedence-700996.patch | 3.19 KB | smk-ka |
| #18 | emogrifier-inline-styles.patch | 3.32 KB | smk-ka |
| #7 | mimemail.700996_01.patch | 935 bytes | sgabe |
Comments
Comment #1
sgabe commentedI can confirm this issue.
simplenews-newsletter-body.tpl.php
mail.css
in the test newsletter the styles are merged just fine
but in the newsletter sent by cron the style is replaced by the definition in mail.css
I'll dig deeper into this.
@-Mania-: Will you help me test if I come up with something?
Comment #2
sgabe commented@-Mania-: Please make sure that Simplenews uses the modified template files. I could reproduce this, when Simplenews couldn't load my custom newsletter template files. I think that is the case in your issue too, so it's not a MimeMail problem after all.
Comment #3
-Mania- commentedThanks sgabe. How exactly do you make sure Simplenews is using the modified template files? It should pick them up when being in the themes folder?
Comment #4
sgabe commentedSimple put something like this in the template file:
You'll have to see it in the message.
Comment #5
-Mania- commentedSorry it took a while to respond. I'm running into the issue you described at #1 over and over again. I am sending test newsletters. All the inline styles get replaced if the mail.css has styles for that element.
I.e. having this in mail.css
Then adding this into simplenews-newsletter-body.tpl.php
Will result in
Any further advice appreciated. I don't know how you managed to get it working correctly! :D
Comment #6
sgabe commentedFollowed your lead in #5 and retested this. Issue confirmed as valid. I missed the bug in my first test...
To reproduce:
The inline property's value will be overwritten with the one defined in mail.css. I couldn't reproduce this at first because I used different properties. In that case the CSS Compressor concatenates the properties just fine.
I am changing the title to a more accurate one.
Comment #7
sgabe commentedCSS Compressor creates arrays from the style attributes, than uses array_merge() to merge the existing style information with the new one. According to the behavior of the function:
I think we can simply commute the two arrays, so the old one will overwrite the new one and we can preserve the existing inline values. I am attaching a patch and changing the version, since patches should be made against HEAD.
@-Mania-: Try the attached patch and report back, please.
Comment #8
-Mania- commentedIt works! You just made me very happy. :)
I actually have a couple of other CSS problems/suggestions but I'll open up separate issues for those.
Comment #9
sgabe commentedPlease, set the issue status to RTBC, if it works.
Comment #10
-Mania- commentedComment #11
sgabe commentedCommitted to HEAD.
Comment #13
sgabe commentedI am afraid we have to revert this commit and find another workaround because this approach ignores the CSS style precedence, see #882960: CSS Mail Style Sheet Overrides for more information.
Comment #14
smk-ka commentedCould you please try #885006: Update Emogrifier (mimemail_compress) instead?
Comment #15
sgabe commentedWell, I didn't test #796510: Update CSS Compressor for this issue, but I can imagine that it solves this issue too. Did you try it?
Comment #16
sgabe commentedI did a quick test and it's not working.
Comment #17
smk-ka commentedYeah, sorry, I missed that issue where the emogrifier update is buried. I've answered this issue's question in the other #796510: without inventing a completely new system, emogrifier doesn't keep inline style properties and always overwrites them. A 'completely new system' could look like retrieving the XPath to all elements with style attribute (before starting to process the CSS styles!) and dynamically adding them to the list of selectors. Since they're full path expressions from the root to the element, they would have the heighest weight and therefore be applied last (after sorting).
Comment #18
smk-ka commentedVoilà, here's a patch that does what I said. For now, it's a patch against the original emogrifier, i.e. if you decide to apply/port it to mime_compress you have to restore the merge order of style attributes first!
Comment #19
sgabe commentedsmk-ka: Please, would you make a patch against current HEAD?
Comment #20
smk-ka commentedThank god it's friday!
Comment #21
sgabe commentedChanging status, since we have a patch that needs testing.
Comment #22
sgabe commented@smk-ka: Sorry that it took me so long to review your patch. I just tested it, applies fine and seems to work fine.
Comment #23
sgabe commentedCommitted, thanks!