dreamvention/inky-premailer
Composer 安装命令:
composer require dreamvention/inky-premailer
包简介
Implementation of ZURB Inky + CssToInlineStyles. Compile responsive emails on the fly with ease.
README 文档
README
ZURB Inky email templating Language + CssToInlineStyles CSS inliner is the perfect match for creating responsive emails.
Example
I made a simple example of how to quickly implement inky-premailer.
Thanks to
- Thampe for providing php implementation of Foundation for Email parser https://github.com/thampe/inky
- tijsverkoyen for making such a wonderful class to convert HTML into HTML with inline styles https://github.com/tijsverkoyen/CssToInlineStyles
Installation
The recommended installation way is through Composer.
$ composer require dreamvention/inky-premailer
or add the package to your composer.json file directly.
Usage
<?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 templating Language
It's really an awesome thing what ZURB Foundation guys have done with inky. Instead of counting all those td's and tr's you now have a dosen of tags and a clean markup.
This is HTML that an email uses to be responsive. Madness, right.
<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>
And this is Inky markup
<container> <row> <columns>Put content in me!</columns> </row> </container>
If you want to start right away using inky go here
Try the example or use ready made templates from Froundation.
Add links to CSS files
You can also add links to CSS files either relative to your root folder or with full address.
<?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;
How CSS is rendered?
- First the styles in your html file are rendered.
- Then if you have added links to CSS, they will be rendered, rewriting styles added eariler.
This sometimes may be tricky so just stick to one way of adding CSS - in the HTML template file or adding CSS links via php.
$links and $styles are optional
License
See the LICENSE file for license info (it's the MIT license).
dreamvention/inky-premailer 适用场景与选型建议
dreamvention/inky-premailer 是一款 基于 HTML 开发的 Composer 扩展包,目前已累计 13.91k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2016 年 10 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 dreamvention/inky-premailer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dreamvention/inky-premailer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 13.91k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-10-01