bamboo v0.4.0 Bamboo.Phoenix

Render templates and layouts with Phoenix.

This module makes it very easy to render layouts and views using Phoenix. Pass an atom (e.g. :welcome_email) as the template name to render HTML and plain text emails. Use a string if you only want to render one type, e.g. "welcome_email.text" or "welcome_email.html".

Examples

defmodule Email do
  use Bamboo.Phoenix, view: MyApp.EmailView

  def text_and_html_email_with_layout do
    new_email()
    # You could also only set a layout for just html, or just text
    |> put_html_layout({MyApp.LayoutView, "email.html"})
    |> put_text_layout({MyApp.LayoutView, "email.text"})
    # Pass an atom to render html AND plain text templates
    |> render(:text_and_html_email)
  end

  def text_and_html_email_without_layouts do
    new_email()
    |> render(:text_and_html_email)
  end

  def email_with_assigns(user) do
    new_email()
    # @user will be available in the template
    |> render(:email_with_assigns, user: user)
  end

  def email_with_already_assigned_user(user) do
    new_email()
    # @user will be available in the template
    |> assign(:user, user)
    |> render(:email_with_assigns)
  end

  def html_email do
    new_email
    |> render("html_email.html")
  end

  def text_email do
    new_email
    |> render("text_email.text")
  end
end

Summary

Functions

Sets an assign for the email. These will be availabe when rendering the email

Sets the layout when rendering HTML templates

Sets the layout when rendering plain text templates

Render a Phoenix template and set the body on the email

Functions

assign(email, key, value)

Sets an assign for the email. These will be availabe when rendering the email

put_html_layout(email, layout)

Sets the layout when rendering HTML templates

put_text_layout(email, layout)

Sets the layout when rendering plain text templates

render(email, template_name, assigns)

Render a Phoenix template and set the body on the email

Pass an atom as the template name to render HTML and plain text emails, e.g. :welcome_email. Use a string if you only want to render one type, e.g. "welcome_email.text" or "welcome_email.html". Scroll to the top for more examples.