How EEx Turns Your Template into HTML
Here is one suave merchandise!!
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
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
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
Fragment this on knowasiak.com to search recommendation from folk on this topicEffect in on Knowasiak.com now while you will no longer be registered yet.