laravel - 如何在 Laravel Markdown Mailable 中生成一个换行符
问题描述
这是可邮寄的模板:
@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>
当您在浏览器中显示此内容时...
地址行 1 地址行 2 地址行 3因此,我已经看到了其他几个关于此的 SO 问题,但它们并没有解决我的问题。我试过在每行后面加上两个空格,也用反斜杠。两者都没有任何效果。
解决方案
首先,总是可以将 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
还有一件事:不要考虑将模板文件中的所有内容重构为通知。通知还支持作为电子邮件发送,并且可以将邮件模板重用于其他电子邮件。(但这不会帮助您了解新线路。)
推荐阅读
- python - 矩形属性似乎不可调用(碰撞)
- java - 如何基于 Avro Schema 将 XML 转换为 AVRO?
- android - spinner的非选中值如何使用?
- c# - 我可以使用 Entity Framework 来跟踪 DataSet 之类的更改(无需连接到数据库)吗?
- excel-formula - 如何从这个公式的所有范围中排除 0?
- kiwi-tcms - GitHub/Kiwi TCMS 集成,无尽的微调器
- r - 如何将图例添加到 hline 和 vline 一起?
- python - 层 conv1d_1 的输入 0 与层不兼容:预期 ndim=3,发现 ndim=2。收到的完整形状:[无,200]
- ios - 当 UITableViewController 嵌套在另一个 UIViewController 中时,“didSelectRowAt indexPath”没有被调用
- node.js - 通过 NPM 与 IntelliJ 运行测试时的速度差异