How to use a text file as an html layout? The same way we use html layouts with child pages

In Phoenix we use html layouts to wrap a content of an html file. Those 2 can be used for creating email pages as well.

I want to create an email pages but in a text format. Not html. And I want to be able to utilize a text layout instead of one in html. That is, I’ll create a text file called base.txt

This is my text layout

blah-blah-blah-blah


<%= content will be placed here %>


 --------
this is the footer
my sign: blah-blah-blah-blah

and for each type of email I want to send I’ll use it as a base layout – the precise same way html emails are used.

Is there an idiomatic way to archive this?

You can create a view file:

defmodule PersonalWebsiteWeb.LayoutView do
  use PersonalWebsiteWeb, :view

  @static_text ~s"""
    bal bla bla
  """
  @dynamic_text ~s"""
    bal bla bla

    <%= my_var %>
  """

  def get_dynamic do
    EEx.eval_string(@dynamic, [
      my_var: "variable replaced"
    ])
  end
  def get_static, do: @static_text
end

and inside your templates use:
<%= PersonalWebsiteWeb.LayoutView.get_static %> or <%= PersonalWebsiteWeb.LayoutView.get_dynamic %>

I hope I understand the problem :slight_smile:

Where did you define @dynamic?

replace @dynamic with @dynamic_text :slight_smile: