在文档之后,我使用可标记邮件创建了自己的邮件模板:https://laravel.com/docs/9.x/mail#generating-markdown-mailables
关键是我需要动态地定制页眉和页脚中的信息(在每种情况下都是不同的)。我在toMail函数中传递的信息仅在我的自定义模板neworder.blade.php的作用域中可用:
public function toMail($notifiable){
$from = 'no-reply.'.$this->subdomain.'@'.env('APP_DOMAIN');
return (new MailMessage)
->from($from)
->markdown('emails.neworder',
[
'name'=>$this->name,
'order'=> $this->order,
'emailbody'=> $this->emailbody,
'headertitle' => $this->headertitle,
'footertext' => $this->footertext
]
);
}在相同的文档之后,我导出了Markdown邮件组件以使用以下命令对它们进行自定义:
php artisan vendor:publish --tag=laravel-mail从这里开始,我可以定制文件,如/header/mail/html/themes/Header.blde.php,其中的修改有效地影响了头文件。我无法理解的是,如何传递变量,就像在/views/email/neworder.blade.php中一样,我可以在这些文件的范围中使用这些变量,我需要在相应的部分中包含headertitle和footertext的值。
发布于 2022-04-05 13:00:46
由于找不到更好的解决方案,我最终被迫使用会话变量,以便在页眉和页脚模板中使用它们。
Http/Notifications/yourNotificationTemplate.php:中要在页脚/页眉中使用的
公共函数toMail($notifiable){ session('headertitle‘=> $this->headertitle);session('footertext’=> $this->footertext);$from =返回(新MailMessage) ->from($from) ->markdown('emails.neworder‘>、’name‘>$this->name、’order‘> $this->order、’emailbody=‘> $this->emailbody、}
中的F.E
@php ($headertext = session('headertitle'))
<tr>
<td class="header">
@if (null!==(session('headertext')))
<h1>{{$headertext}}</h1>
@else
{{ $slot }}
@endif
</td>
</tr>https://stackoverflow.com/questions/71486062
复制相似问题