dreamvention / inky-premailer
ZURB Inky + CssToInlineStyles的实现。轻松实现即时编译响应式邮件。
1.0.2
2016-10-02 13:17 UTC
Requires
- php: >=5.4.0
- hampe/inky: 1.3.6.2
- paquettg/php-html-parser: ^1.7
- tijsverkoyen/css-to-inline-styles: ^2.2
This package is not auto-updated.
Last update: 2024-09-28 20:09:06 UTC
README
ZURB Inky 邮件模板语言 + CssToInlineStyles CSS内联器是创建响应式邮件的完美选择。
示例
我制作了一个简单的示例,展示如何快速实现 inky-premailer。
感谢
- Thampe 为提供 Foundation for Email 解析器的 PHP 实现https://github.com/thampe/inky
- tijsverkoyen 为制作将 HTML 转换为带有内联样式的 HTML 的出色类https://github.com/tijsverkoyen/CssToInlineStyles
安装
推荐安装方式是通过 Composer。
$ composer require dreamvention/inky-premailer
或者直接将包添加到您的 composer.json 文件中。
使用方法
<?php use Dreamvention\InkyPremailer\InkyPremailer; $inkyPremailer = new InkyPremailer(); $html = '<html><head><style>body{ background:#ccc; } .hello{ color:red; }</style></head><body><div class="hello">Hello World</div></body></html>'; $email = $inkyPremailer->render($html); echo $email;
Inky 模板语言
ZURB Foundation 的团队在 inky 上做了很棒的事情。您现在只需要使用一些标签和干净的标记,而不是去数那些 td 和 tr。
这是电子邮件使用的响应式 HTML。疯狂,对吧。
<table align="center" class="container"> <tbody> <tr> <td> <table class="row"> <tbody> <tr> <th class="small-12 large-12 columns first last"> <table> <tr> <th>Put content in me!</th> <th class="expander"></th> </tr> </table> </th> </tr> </tbody> </table> </td> </tr> </tbody> </table>
这是 Inky 标记
<container> <row> <columns>Put content in me!</columns> </row> </container>
如果您想立即开始使用 inky,请访问这里
添加 CSS 文件的链接
您也可以添加到 CSS 文件的链接,可以是相对于您的根文件夹的,也可以是完整地址。
<?php use Dreamvention\InkyPremailer\InkyPremailer; $inkyPremailer = new InkyPremailer(); $html = '<html><head><style>body{ background:#ccc; } .hello{ color:red; }</style></head><body><div class="hello">Hello World</div></body></html>'; $links = array(); $links[] = 'css/style.css'; // this will override the styles in the template file. $styles = '.header { background:#fff; }'; //this is the final styles that will overwrite all the others. $html = file_get_contents('template/basic.html'); $email = $inkyPremailer->render($html, $links, $styles); echo $email;
CSS 如何渲染?
- 首先,渲染您的 HTML 文件中的样式。
- 然后,如果您添加了 CSS 链接,它们将被渲染,并重写之前添加的样式。
这有时可能有点棘手,所以请坚持一种添加 CSS 的方式 - 在 HTML 模板文件中添加,或者通过 PHP 添加 CSS 链接。
$links 和 $styles 是可选的
许可证
有关许可证信息,请参阅LICENSE 文件(它是 MIT 许可证)。