How EEx Turns Your Template into HTML

How EEx Turns Your Template into HTML

Hello reader! Welcome, let's start-

Here is one suave merchandise!!

EEx is a templating language and module constructed into the Elixir odd library, customarily dilapidated by web servers to render dynamic convey for a web application. The an identical theory exists in varied language ecosystems, ERB for Ruby, Blade for Laravel/PHP, Pug/Jade for JavaScript.

A pair parts of EEx that produce it stand out are:

  • Templates is at possibility of be compiled into capabilities earlier than time, maintaining off desirous to learn from the file machine at runtime.
  • EEx has the theorem that of an “Engine” allowing you to assemble an reward template into one thing varied than what the builtin engine, EEx.SmartEngine, does. Here is what Phoenix LiveView does.

Just no longer too long within the past, José Valim tweeted me some recommendation on the model to exercise the EEx Engine in my library Temple (an different HTML library, that makes exercise of an Elixir DSL). At the origin I changed into as soon as very puzzled at José’s recommendation; I don’t must write EEx in any appreciate! I need Temple to spin from DSL straight to iolist or %LiveView.Rendered{} structs.

Fortunately, my coworker Marlus Saraiva messaged me and gave somewhat extra context on José’s recommendation, and it all clicked!. (Expectantly on the tip of this post, you’ll realize how José’s recommendation makes finest sense and changed into as soon as extraordinarily definite.)

This conversation led me to demand myself, how does EEx work anyway? I obvious to source dive EEx, LiveView, Ground, and HEEx and will share with you what I learned!

The Source Code

Technically EEx is exclusively a templating syntax that can tackle any plaintext format. It doesn’t topic if its HTML, JavaScript, and even Elixir (this is how the Phoenix mills work).

EEx templates will let you whole arbitrary Elixir code within of special tags and inject the runtime outcome into the return worth. It is doubtless you will likely exercise single expressions and even expressions that snatch blocks. The EEx.SmartEngine also permits you to ergonomically entry recordsdata handed to the template with the @ syntax.

 @particular person.n

Read More
Fragment this on to search recommendation from folk on this topicEffect in on now while you will no longer be registered yet.

About the author: Vanic
“Simplicity, patience, compassion. These three are your greatest treasures. Simple in actions and thoughts, you return to the source of being. Patient with both friends and enemies, you accord with the way things are. Compassionate toward yourself, you reconcile all beings in the world.” ― Lao Tzu, Tao Te Ching

Get involved!

Get Connected!
One of the Biggest Social Platform for Entrepreneurs, College Students and all. Come and join our community. Expand your network and get to know new people!


No comments yet
Knowasiak We would like to show you notifications so you don't miss chats & status updates.
Allow Notifications