Book Image

Elixir Cookbook

By : Paulo Pereira
Book Image

Elixir Cookbook

By: Paulo Pereira

Overview of this book

Table of Contents (16 chapters)
Elixir Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating views and templates


After the router determines the right controller and action to handle a request after the controller performs all the tasks to prepare data to respond to the request, it generally needs to output that data. In the previous recipe, we saw how a controller could respond by rendering test and outputting static HTML or even JSON. What if we need to generate an HTML response and that HTML must be dynamic, depending on the values passed by the controller?

Before we proceed, there is one thing we have to make clear for those coming from other frameworks: the view is not an HTML (or other markup) file. Views mainly render templates but they are also responsible for providing functions that make data easier to consume by templates. In Phoenix, a view is more like a decorator.

We may also use templates and layouts. Templates are the HTML structure where data obtained via the controller and prepared by the view is displayed. Layouts are a way to define a common structure...