Customizing the Markdown email template in Laravel

It’s possible that we need a bit more control over our markdown email templates. Maybe we want to hide the header or the footer, but we can’t achieve that on the usual way.

Usually, we use the @component (‘mail::message’) component to handle markdown templates. The documentation provides a nice and detailed description of how to use them.

Note: when using markdown mailable pay attention to your indentation. The indented text is recognized as a code formatted block.

However what if we want have a bit more flexibility, like hiding the header or the footer or customize it a  little more? The trick is to use another component instead of the mail::message.

@component('mail::layout')
{{-- Header --}}
@slot ('header')
@component('mail::header', ['url' => config('app.url')])
    <!-- header -->
@endcomponent
@endslot

{{-- Content here --}}

{{-- Subcopy --}}
@slot('subcopy')
@component('mail::subcopy')
<!-- subcopy -->
@endcomponent
@endslot

{{-- Footer --}}
@slot ('footer')
@component('mail::footer')
<!-- footer -->
@endcomponent
@endslot
@endcomponent

As you can see, we can put our on component content. So if we want to hide the header, subcopy or footer partials we can just leave the content of their slot. Not a big deal, however in some cases this approach can be very useful, especially if we are handling various types of emails.

Need a web developer? Maybe we can help, get in touch!