From 31c8ebe842fe8a821c56ec6b79f5eb1b4c982bd2 Mon Sep 17 00:00:00 2001 From: Robert Date: Tue, 8 Nov 2022 19:17:47 +0200 Subject: [PATCH] add a default base_email layout to every email --- lib/plausible_web/email.ex | 12 +++++++++- .../templates/layout/base_email.html.eex | 24 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 lib/plausible_web/templates/layout/base_email.html.eex diff --git a/lib/plausible_web/email.ex b/lib/plausible_web/email.ex index 08568f929..70041a0a7 100644 --- a/lib/plausible_web/email.ex +++ b/lib/plausible_web/email.ex @@ -305,11 +305,21 @@ defmodule PlausibleWeb.Email do }) end - defp base_email() do + defp base_email(), do: base_email(%{layout: "base_email.html"}) + + defp base_email(%{layout: layout}) do mailer_from = Application.get_env(:plausible, :mailer_email) new_email() |> put_param("TrackOpens", false) |> from(mailer_from) + |> maybe_put_layout(layout) + end + + defp maybe_put_layout(email, nil), do: email + + defp maybe_put_layout(email, layout) do + email + |> put_html_layout({PlausibleWeb.LayoutView, layout}) end end diff --git a/lib/plausible_web/templates/layout/base_email.html.eex b/lib/plausible_web/templates/layout/base_email.html.eex new file mode 100644 index 000000000..c13e1a21b --- /dev/null +++ b/lib/plausible_web/templates/layout/base_email.html.eex @@ -0,0 +1,24 @@ +<%= case Map.get(assigns, :user) do + %{name: name} when is_binary(name) -> "Hey #{String.split(name) |> List.first()}," + _any -> "Hey," +end %> +

+ +<%= @inner_content %> +

+ +Thanks,
+<%= if Application.get_env(:plausible, :is_selfhost) do %> +Plausible +<% else %> +Uku and Marko +<% end %> +

+ +-- +

+<%= link(plausible_url(), to: plausible_url()) %>
+ +<%= if Map.get(assigns, :unsubscribe, false) do %> +{{{ pm:unsubscribe }}} +<% end %>