我尝试使用 Laravel 5.1 来使用部分和模板,但是发送电子邮件时 HTML 模板不会被解析。
例如,以下代码会导致仅发送 content
部分,而不会发送 HTML 模板 (emails.template
);
@extends('emails.template')
@section('content')
Hi there!<br><br>
Please click on the link below to reset your password:<br><br>
{{ url('password/reset/'.$token) }}<br><br>
<strong>Note:</strong> This is an automatically generated email, please do not reply.
@endsection
我的 emails/template.blade.php
文件如下所示:
@yield('header')
@yield('content')
@yield('footer')
我可能做错了什么?
最佳答案
如图所示,问题在于您的布局需要扩展它的 View 来定义“页眉”、“内容”和“页脚”部分。由于您的 View 仅定义了“内容”部分,因此这就是将要显示的全部内容。
如果您想显示 emails/header.blade.php
和 emails/footer.blade.php
部分内容,则这不是正确的语法。为此,您需要 @include
这些部分。不过,如果您希望 View 能够覆盖它们,则可以将它们包含在部分内。
您正在寻找类似以下内容:
@section('header')
@include('emails.header')
@show
@yield('content')
@section('footer')
@include('emails.footer')
@show
现在,您的“页眉”和“页脚”部分将默认为 emails/header.blade.php
和 emails/footer.blade.php
中包含的内容> 文件,但仍然可以通过定义自己的“页眉”和“页脚”部分在实际 View 中覆盖(或附加)它们。
关于php - Laravel 5.1 电子邮件 View 和模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35176323/