Maarten Raaijmakers
Maarten Raaijmakers

Reputation: 645

Laravel Mailable Markdown Header + Footer

I would like to change the content of my header and footer slot in mailables.

What I have in template.blade.php is:

@component('mail::message')
{{ $message }}
@endcomponent

In my message.blade.php

@component('mail::layout')
    {{-- Header --}}
    @slot('header')
        @component('mail::header')
            {{ $preheader }}
        @endcomponent
    @endslot

    {{-- Body --}}
    {{ $slot }}

    {{-- Subcopy --}}
    @isset($subcopy)
        @slot('subcopy')
            @component('mail::subcopy')
                {{ $subcopy }}
            @endcomponent
        @endslot
    @endisset

    {{-- Footer --}}
    @slot('footer')
        @component('mail::footer')
            $footer
        @endcomponent
    @endslot
@endcomponent

Which is called with:

    return $this
        ->to($this->user->email)
        ->subject($this->config['subject'])
        ->from($this->config['from']['email'])
        ->markdown('emails.template', ['preheader' => $this->config['preheader'], 'footer' => $this->config['footer'], 'message' => $this->config['message']]);

However this is not putting the preheader and the footer at the place where I want it. How should I adjust my files accordingly so that this does happen?

Upvotes: 2

Views: 5411

Answers (2)

Watercayman
Watercayman

Reputation: 8168

If anyone else came here banging their head against the wall, after having no changes to either the messages files or the header/footer files show up, @Zsolt has provided the clue in the accepted answer. I kept making changes to the markdown files, but they never showed up - almost like Laravel was pointing to the wrong place. And it was...

If, like me, you are working on an upgraded Laravel application (I.E. you started with 5.x and have upgraded over time), there are two potential issues.

First, in ip/config/mail.php: you may have to actually create the markdown path. If you published the mailables prior to markdown, the entire markdown mail settings are missing. You can pull them from the git repo, or from here for convenience:

'markdown' => [
    'theme' => 'default',
    'paths' => [
        resource_path('views/vendor/mail'),
    ],
],

Second issue if you published these mail files earlier, the Laravel layouts file in the HTML directory has the or operator, which will choke. Change these three operators to ??.

Upvotes: 3

Zsolt Janes
Zsolt Janes

Reputation: 840

So, run this command:

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

After that you will have some files in the following folder:

resources/views/vendor/mail/

Now you are able to edit the header.blade.php and footer.blade.php

resources/views/vendor/mail/html/header.blade.php
resources/views/vendor/mail/html/footer.blade.php

The CSS file can be found here:

resources/views/vendor/mail/html/themes/default.css

You can make custom HTML and CSS here: https://markdownmail.com

Don't forget to change the config/mail.php makdown paths:

resource_path('views/vendor/mail'),

Upvotes: 4

Related Questions