petecoop/laravel-inky

Laravel 中使用 Foundation Inky 邮件模板

0.5.2 2018-02-08 22:00 UTC

This package is auto-updated.

Last update: 2024-09-27 20:38:19 UTC


README

Build Status

允许您在 Laravel 5 中优雅地使用 Foundation 的 Inky 邮件模板。

任何扩展名为 .inky.php 的视图都将与 Inky 和 Blade 一起编译,让您可以无缝地一起使用这两个模板引擎。CSS 将自动内联,以便在不支持外部样式表的电子邮件客户端中工作。

安装

使用 Composer 需求

composer require petecoop/laravel-inky

安装完成后,您需要注册服务提供者。打开 config/app.php 并将以下内容添加到 providers

Petecoop\LaravelInky\InkyServiceProvider::class

使用方法

有关如何使用 Inky 和 Foundation for Emails CSS 的完整使用方法,请参阅 Foundation for Emails 文档

创建一个 Inky 视图,例如 emails/welcome.inky.php

<container>
  <row>
    <columns>Welcome, {{ $name }}</columns>
  </row>
</container>

像往常一样在 Laravel 中使用 Mail

Mail::send('emails.welcome', ['name' => $user->name], function ($m) use ($user) {
  $m->from('hello@app.com', 'Your Application');

  $m->to($user->email, $user->name)->subject('Welcome!');
});

您可以创建一个继承的 Blade 布局,例如 emails/layout.inky.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="viewport" content="width=device-width"/>
  <link rel="stylesheet" href="foundation-emails.css">
</head>
<body>
  @yield('content')
</body>
</html>

然后

@extends('emails.layout')

@section('content')
  <container>
    <row>
      <columns>Welcome, {{ $name }}</columns>
    </row>
  </container>
@stop

CSS 内联

<style><link rel="stylesheet"> 将自动内联。

您的 <link rel="stylesheet"> href 位置将解析为 resources/assets/css 目录,因此在上面的示例中,它期望在 resources/assets/css/foundation-emails.css 中有一些 CSS。

以下是一个关于电子邮件中 CSS 的便捷参考: 电子邮件客户端 CSS 支持指南

许可证

MIT 许可证