Why Phoenix templates make web development so great?

Why Phoenix templates make web development so great?
Average rating: 0
(0 votes)

Thanks! You’ve rated this material!

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 therender/n functions. While the base function resides in the Phoenix.View module, 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!

Rate this article, if you like it

Thanks! You’ve rated this material!

Got a project? Let's discuss it!

*By submitting this form you agree with our Privacy Policy.

Mailing & Legal Address

Syndicode Inc. 340 S Lemon Ave #3299, Walnut CA, 91789, USA

Visiting & Headquarters address
Kyiv Sofiivska 1/2a, 01001, Kyiv, Ukraine
Dnipro Hlinky 2, of. 1003, 49000, Dnipro, Ukraine
Email info@syndicode.com
Phone (+1) 9035021111