This repository has been archived by the owner on Apr 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
89 lines (67 loc) · 3.59 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
Newsletter Export is a Drupal module which allows one or more specific node
type to be exported as raw HTML. This is excellent for building a node type
to use as a newsletter. We generally use the References or Entity References
module to collect other content/articles into the export. The general
approach and how to set up your content type is explained here:
http://www.freeform.ca/en/blog/updated-recipe-building-newsletters-drupal-7
Visit admin/config/media/newsletter_export to choose the content types.
A new display mode "newsletter" is then available on those content types
so you can create a unique field arrangement and markup just for the
newsletter export.
Templates:
-------------------------------------------------------------------------------
The template file or files allow you to customize the output of your fields.
Move or copy newsletter-export.tpl.php to your theme folder to edit.
1) Template File (By default applies to all active newsletter content types):
newsletter-export.tpl.php
2) Copy Template File (for a particular content type):
newsletter-export--my_node_type.tpl.php
EG. newsletter-export--newsletter.tpl.php
The template provides three variables
$raw_markup -> The raw markup that drupal would provide for your node,
outputs everything with one easy print statement.
$fields -> An array of all the fields and their values
$node -> The entire node object
The default template uses $raw_markup. One example of how to use the individual
fields wrapped with html and inlined css is shown below and with more detail on:
https://drupal.org/node/2045961
<html>
<head></head>
<body>
<h1 style="font-size: 16px; font-weight: bold; color: navy; margin-bottom: 10px;"><?php print $fields['title']; ?></h1>
<div style="font-size 10px;"><?php print $fields['body']['und'][0]['safe_value']; ?></div>
<hr/>
<?php foreach ($fields['field_news_latest_pages']['und'] as $delta => $news_item): ?>
<?php $ent = $news_item['entity']; ?>
<div style="font-size 10px; border-bottom: 1px dotted #808080;">
<?php print $ent->body['und'][0]['safe_value']; ?>
</div>
<?php endforeach; ?>
</body>
</html>
Note though that currently, relative URLs in content are only changed to absolute URLs in
$raw_markup. So if you want to use $fields or $node, you may have to add some code to
your template to address this issue.
Automatically inlining the css:
-------------------------------------------------------------------------------
Email clients are notorious for ignoring css. This includes major clients like
Gmail. If you want to use $raw_markup to ouput your content rather than make a
custom template it will output woth the ids and classes from your sites template
but no inline css. You can then use a third-party service to turn your html file
with css to inline styles that will look good in most email clients.
E.g. http://premailer.dialect.ca/, http://inlinestyler.torchboxapps.com/.
You'll have to upload the exported newsletter file to the site to have it converted.
Or call a script like https://github.com/tijsverkoyen/CssToInlineStyles to
transform it before downloading.
Upload the script to the newsletter_export module.
In top of newsletter-export.tpl.php include the script. E.g.:
module_load_include('php', 'newsletter_export', 'CssToInlineStyles/css_to_inline_styles');
Add your css as a string. E.g.:
$css = 'h1 { background: green;}';
Run the html and css through the script.
$current_html = new CSSToInlineStyles($raw_markup,$css);
$processed_html = $current_html->convert();
Then replace:
<?php print $raw_markup; ?>
with:
<?php print $processed_html; ?>