I am trying to use @foreach
loop inside markdown template for sending mails.
While using HTML tags inside @foreach, it is not rendered properly
@component('mail::message')
These are the latest contents in our website
@foreach($results as $type => $result)
<h4>{{ $result['name'] }}</h4>
@endforeach
Thanks,<br>
{{ config('app.name') }}
@endcomponent
In the received mail, the <h4>
tag will be displayed as,
<h4>Article</h4>
Markdown is not getting processed when it's placed inside @foreach
loop. But it's processed when placed outside @foreach
loop.
Any help will be much appreciated. Thanks.
Good question, the same applies with an example using markup instead of html. For example:
Can result in:
While with 2 spaces indentation instead of 4 like so
The same input results in:
as intended and explained by @Ben pointing to https://laravel.com/docs/5.8/mail#writing-markdown-messages
As stated in laravel documentation:
The problem is not the HTML tags put inside the
@foreach
, but the indentation makes parsers render as follows (I am using markdown now, 4 spaces before<h4>
):