Customizing the Markdown email template in Laravel

LaravelPosted on

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.

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

{{-- Content here --}}

{{-- Subcopy --}}
<!-- subcopy -->

{{-- Footer --}}
@slot ('footer')
<!-- footer -->

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!

Similar Posts

More content in Laravel category