Hanami trick: Default template for mailers

Rogério Zambon
1 min readMar 22, 2016

First of all, if you don’t know what is the Hanami, a great framework, click here.

For now, we don’t have a simple way to define layouts to our email templates. However, we can set a default template (or default content) to be used in email templates. To do this, I’ve created a module like this:

PS: It’s mandatory to define root property in Hanami::Mailer configuration.

So now, the Mailers::DefaultTemplate module should be included in prepare block, like this:

It’s done. In email templates, you can add default_template method to include a default content, like this:

<%= default_template %>Hi there, it works!Best,

I hope this helps you!

--

--