gpt4 book ai didi

php - 干净地 emogrify Laravel Blade 模板文件的最佳方法是什么?

转载 作者:可可西里 更新时间:2023-10-31 23:50:47 24 4
gpt4 key购买 nike

我正在使用 an emogrifier格式化 Blade 模板的结果,以便我可以通过电子邮件发送它。

$html = View::make('emails.notification', [
'data' => $data
]);

$emogrifier = new Emogrifier($html, null);

$result = $emogrifier->emogrify();

// now I can send the result in an email...

这按预期工作,但为了干净的代码和可测试性,我想扩展我的 Blade 模板以在模板本身内 emogrify HTML。像这样:

@emogrify
<style>
.red-text {
color: red;
}
</style>
<p class="red-text">This text is red</p>
@endemogrify

...但看起来 Blade 指令不允许像这样打开/关闭标签。有没有更好的方法来完成这个?

最佳答案

这是我在 laravel 中制作电子邮件 Blade 的方法(我通常不使用 emogrifier,但希望这对您有所帮助):

Create a base email blade (usually in resources/views/emails/email.blade.php):

<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">

<style>
/* Include styles for all emails here */
</style>

@section('head')
@show

</head>

<body>

<div class="email-body">
@section('body')
@show
</div>

</body>
</html>

然后,当我想创建电子邮件时,我会展开 Blade :

Create a new file in resources/views/emails/new-user-email.blade.php:

@extends('emails.email')

@section('head')
<style>

/* Add additional styling here if you need to! */

</style>
@stop

@section('body')

<!-- Email body content here! -->
<h1>Welcome new user!</h1>

@stop

关于php - 干净地 emogrify Laravel Blade 模板文件的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42254346/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com