Framework: Button component not correctly rendered inside @if statements

Created on 27 Sep 2017  路  8Comments  路  Source: laravel/framework

  • Laravel Version: 5.4.27
  • PHP Version: 5.6 and 7.0
  • Database Driver & Version: MySQL 5.5.54

Description:

Inside of my markdown email template, I am wrapping a button component inside of an @if statement.

When doing so, the button is rendering the raw HTML inside of the email and not the actual button.

Steps To Reproduce:

@component('mail::message')
# Hello, {{ $user->forename }}

{{ $email->body }}

@if($email->responsable)
    @component('mail::button', ['url' => route('responses.create', $email)])
        Submit Response
    @endcomponent
@endif
@endcomponent

Here's what the email is rendering...

jednutu

But, if I take the button component outside of the if statement as shown above, the button is correctly rendered.

Here's how it looks without the if statement...

screen shot 2017-09-27 at 14 57 39

I've been searching around and asked on Larachat etc. but cannot find out why this happening.

Most helpful comment

screen shot 2017-09-28 at 1 09 45 pm

Don't use indentation in your markdown templates.

All 8 comments

Seems related to #17333 but republishing mail files does not resolve my issue using:

php artisan vendor:publish --tag=laravel-mail

Upgraded to Laravel v5.4.36 too, still occurring. Not ready to upgrade to 5.5 yet, unless there is a fix available in 5.5 then I will have to.

Just to clarify; your first image isn't the view of the source, but an image of the actual rendered content? As in; it is shown as source code, and not rendered html in your mail?

Yes that鈥檚 correct, the actual source is the button wrapped in code and pre tags? Which is why I assume it shown in the rendered email.

Hi @JoeDawson

I was able to recreate your issue and this worked out for me:

@component('mail::message')
# Hello, {{ $user->forename }}

{{ $email->body }}

@if($email->responsable)
@component('mail::button', ['url' => route('responses.create', $email)])
    Submit Response
@endcomponent
@endif
@endcomponent

Let me know if it worked out for you. (Notice the indentation)

Hey @Pauly-,

That worked! I assume because my template is markdown it's parsing the indentation is a code block, rather than me trying to keep my code readable lol.

And I guess it's also nothing directly related to my if statement, just a matter of how it's indented. Regardless of the directive used.

Appreciate the help.

@JoeDawson

Yes, I bet your assumptions are correct.

No problem.

screen shot 2017-09-28 at 1 09 45 pm

Don't use indentation in your markdown templates.

@pactode

That's Worked. Thank You.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jackmu95 picture jackmu95  路  3Comments

felixsanz picture felixsanz  路  3Comments

kerbylav picture kerbylav  路  3Comments

CupOfTea696 picture CupOfTea696  路  3Comments

RomainSauvaire picture RomainSauvaire  路  3Comments