Framework: Foreach in email template breaks layout (CommonMark)

Created on 10 Jan 2020  路  5Comments  路  Source: laravel/framework

  • Laravel Version: 6.10.1
  • PHP Version: 7.3.5
  • Database Driver & Version: not applicable

Description:

After switching to CommonMark under the hood in 6.10, using foreach in an e-mail template breaks the e-mail layout. This is not the same issue as reported in #31081 and #31065 .

Tested with league/commonmark 1.1.2 & 1.2.0

@foreach (['name', 'email', 'telephone'] as $prop)
## {{ $prop }}
@component('mail::panel')
{{ $model->{$prop} }}
@endcomponent
@endforeach

test1

Adding an empty line before closing the foreach seems to fix the issue.

@foreach (['name', 'email', 'telephone'] as $prop)
## {{ $prop }}
@component('mail::panel')
{{ $model->{$prop} }}
@endcomponent

@endforeach

test2

bug

Most helpful comment

The default template within Laravel will be fixed in the next release: https://github.com/laravel/framework/commit/02a326ce5641b741fafb017f3d02b8917ba5e563

However, any existing exported views need to be updated manually. Please see the discussion in the linked issue above.

All 5 comments

After further testing this appears to be a bug in CommonMark.

image

Thanks for taking the time to investigate the issue

The default template within Laravel will be fixed in the next release: https://github.com/laravel/framework/commit/02a326ce5641b741fafb017f3d02b8917ba5e563

However, any existing exported views need to be updated manually. Please see the discussion in the linked issue above.

I see that this has been closed, however I have noticed that this sometimes, randomly happens.

It has caused me to get this error in Horizon.

Symfony\Component\Debug\Exception\FatalThrowableError: Class 'League\CommonMark\Environment' not found in /opt/bitnami/apache2/htdocs/vendor/laravel/framework/src/Illuminate/Mail/Markdown.php:103

What is more strange is that it doesn't happen every time an email is sent out, not with any specific mailable, just every now and again it kicks back an error. I have upgraded Laravel to 6.12.0 but the problem still seems to be there.

So I suppose my question is do we need to make sure to respect the "blank line rule" in our own mail.blade.php files?

Thanks for your help

Was this page helpful?
0 / 5 - 0 ratings

Related issues

felixsanz picture felixsanz  路  3Comments

kerbylav picture kerbylav  路  3Comments

shopblocks picture shopblocks  路  3Comments

RomainSauvaire picture RomainSauvaire  路  3Comments

iivanov2 picture iivanov2  路  3Comments