We already introduced how you can use Elixir and Phoenix for building extremely high performance and low maintenance system. Now we are ready to answer the question why Phoenix templates make web development so great?
If templates are a kind of function, then it stands to reason that there must be ways to both “call” them and pass information to them. In Phoenix we do that with the
render/n functions. While the base function resides in the
Phoenix.Controller has its own version, and of course, templates have access to the
render/3 function provided by their View.
Unlike rendering from controllers, templates provided to views must include the file type as part of the name (e.g. “index.html”, “show.json”, “list.txt”). Phoenix will pattern match against a
render function in the view, or failing that find the matching template located in the directory matching the view’s name. Unless you use an alternative rendering engine, all templates must also have a
.eex appended to their filenames in their respective template directory.
Here are the four reasons you will want to extract templates:
1. To Share Templates
2. To Improve Readability
3. To Encapsulate (i.e. Hide) Logic
4. To Simplify Responsibility
To know more about how typical layout looks like check here.
Phoenix is great! But there are more alternative Elixir frameworks you could not know about. Explore them!