How EEx Turns Your Template into HTML

How EEx Turns Your Template into HTML

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.

Related Articles

What’s recent in Emacs 28.1?

By Mickey Petersen It’s that time again: there’s a new major version of Emacs and, with it, a treasure trove of new features and changes.Notable features include the formal inclusion of native compilation, a technique that will greatly speed up your Emacs experience.A critical issue surrounding the use of ligatures also fixed; without it, you…

x86 Is an Octal Machine

# source: From: (Mark Hopkins) Newsgroups: alt.lang.asm Subject: A Summary of the 80486 Opcodes and Instructions (1) The 80×86 is an Octal Machine This is a follow-up and revision of an article posted in alt.lang.asm on 7-5-92 concerning the 80×86 instruction encoding. The only proper way to understand 80×86 coding is to realize that…

Windows 11 Guide

A guide on setting up your Windows 11 Desktop with all the essential Applications, Tools, and Games to make your experience with Windows 11 great! Note: You can easily convert this markdown file to a PDF in VSCode using this handy extension Markdown PDF. Getting Started Windows 11 Desktop Bypass Windows 11’s TPM, CPU and…

Used CSS, Original CSS

I first got into web design/development in the late 90s, and only as I type this sentence do I realize how long ago that was. And boy, it was horrendous. I mean, being able to make stuff and put it online where other people could see it was pretty slick, but we did not have very…