首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Laravel标价邮件中的动态页眉和页脚

Laravel标价邮件中的动态页眉和页脚
EN

Stack Overflow用户
提问于 2022-03-15 16:53:35
回答 1查看 1.1K关注 0票数 1

在文档之后,我使用可标记邮件创建了自己的邮件模板:https://laravel.com/docs/9.x/mail#generating-markdown-mailables

关键是我需要动态地定制页眉和页脚中的信息(在每种情况下都是不同的)。我在toMail函数中传递的信息仅在我的自定义模板neworder.blade.php的作用域中可用:

代码语言:javascript
复制
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邮件组件以使用以下命令对它们进行自定义:

代码语言:javascript
复制
php artisan vendor:publish --tag=laravel-mail

从这里开始,我可以定制文件,如/header/mail/html/themes/Header.blde.php,其中的修改有效地影响了头文件。我无法理解的是,如何传递变量,就像在/views/email/neworder.blade.php中一样,我可以在这些文件的范围中使用这些变量,我需要在相应的部分中包含headertitlefootertext的值。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-04-05 13:00:46

由于找不到更好的解决方案,我最终被迫使用会话变量,以便在页眉和页脚模板中使用它们。

Http/Notifications/yourNotificationTemplate.php:中要在页脚/页眉中使用的

  1. 设置会话变量

公共函数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、}

  1. ,那么您可以在模板中的任何地方使用它。/views/vendor/mail/thml/header.blade.php:

中的F.E

代码语言:javascript
复制
@php ($headertext = session('headertitle'))
<tr>
<td class="header">
@if (null!==(session('headertext')))
<h1>{{$headertext}}</h1>
@else
{{ $slot }}
@endif
</td>
</tr>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71486062

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档