如何在Laravel Markdown Mailable中生成单个换行符

时间:2019-02-02 22:20:38

标签: laravel markdown

下面是可邮寄模板:

@component('mail::message')
Address line 1
Address line 2
Address line 3
@endcomponent

这是生成的HTML:

<p style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box; color: #74787E; font-size: 16px; line-height: 1.5em; margin-top: 0; text-align: left;">Address line 1
Address line 2
Address line 3</p>

当您在浏览器中显示此内容时...

地址第一行 地址行2 地址行3

因此,我在此上看到了其他几个SO问题,但是它们并没有解决我的问题。我曾尝试以下有两个空格的每一行,并用反斜杠。都没有任何作用。

1 个答案:

答案 0 :(得分:2)

首先,始终可以将markdown和HTML组合在一起:

@component('mail::message')
Address line 1<br>
Address line 2<br>
Address line 3<br>
@endcomponent

另一种方法是使用换行符\n并用nl2br()进行解析:

@component('mail::message')
{!! nl2br("Address line 1\n Address line 2\n Address line 3") !!}
@endcomponent

注意:nl2br()仅在字符串用双引号引起来时有效!

我也喜欢表组件:

@component('mail::table')
| Addresses      |
| -------------- |
| Address line 1 |
| Address line 2 |
| Address line 3 |
@endcomponent

另一件事:不要将所有内容包含在模板文件中,而是考虑重构为notifications。通知还支持作为电子邮件发送,并可以将邮件模板重用于其他电子邮件。 (不过,这对新行无济于事。)

相关问题