_rubenfa
What does your ideal version of Phoenix look like - fork - template engine
I love almost every part of Phoenix, except one: the template engine.
As a .NET developer, I have suffered in my skin the difference between template engines. In .NET MVC world we have the Razor that uses a more optimized and friendly way to write server code into templates. With a simple @, you can create any HTML element, use helpers and data model. It would be awesome to have a similar engine on the Phoenix framework.
Most Liked
_rubenfa
I have worked many years with ASP .NET so maybe my opinion is a little bit conditioned.
HTML is a markup language that uses <> symbols a lot. If you are using the same characters in your template engine, in some way you are obfuscating your HTML. When the template is short and clean, it does not matter. But some times the views are very complex and are far cleaner and easy to read if you avoid using <%= to write your Elixir (Ruby or PHP) code.
Here is a bigger example from ASP .NET Core docs:
For me, it’s much cleaner than Phoenix templates. It’s much more easy to see where is the server code and where the HTML code.
But with ASP .NET Core (the last version) you can also use tag helpers that are much more HTML friendly. The same example with tag helpers:
The asp-* tags are the server code, and they do not interfere with HTML code, so it’s much cleaner and easy to read.
OvermindDL1
Just as a suggestion, if you could try to refrain from posting pictures of text it would be awesome, I’m often in a gui-less terminal and having to bring up the post on my phone just to realize the picture was text that could have been included in the post itself wastes a lot of time, plus you can’t highlight it, search for it, etc… ^.^;
EEX isn’t an html template language, it’s a text template language, and removing text that was explicitly put in the file would be very very bad for a variety of formats, even in HTML whitespace is very important, not just in <pre> tags but in a variety of other areas depending on CSS and javascript and all. Just casually wiping whitespace is pretty bad.
If you are wanting something more HTML-specific for templating then there are alternative template engines (and you can mix and match all you want too), like you might like:
Which looks like:
doctype html
html
head
meta name="keywords" description="Slime"
title = site_title
javascript:
alert('Slime supports embedded javascript!');
body
#id.class
ul
= Enum.map [1, 2], fn x ->
li = x
It keeps proper HTML, it uses selector tags to define elements, it uses = to delinate Elixir calls, etc… etc… It’s always looked interesting to me, but I’m too used to looking at html itself. ^.^
There is also django-like template and pug-like templates and more for elixir/phoenix as well, and it’s not hard to create your own either.
As for @ as a trigger key, that seems to only work for single line expressions, giving no control over how to handle output wrapping afterwards or how to handle multi-expressions or bindings or so? I prefer beginning and end delimiters, though I could see @(...) being useful.
_rubenfa
Avoid <%= %> syntax is a good improvement (one character vs five), because it is less intrusive, and more HTML friendly. If other people are doing front-end in your project (designers or front-end developers), it’s better because it does not interfere so much with the real HTML. And if you are working alone or doing front and back-end is less error prone than the current syntax.
For example, this piece of code:
<h1>Users</h1>
<%= link "New User", to: new_user_path(@conn, :index) %>
<ul>
<%= for user <- @users do %>
<li><%= user.name %> (<%= user.age %>)</li>
<% end %>
</ul>
Could be something shorter and easy to read if were:
<h1>Users</h1>
@link "New User", to: new_user_path(@conn, :index)
<ul>
@for user <- @users do
<li>@user.name (@user.age)</li>
end
</ul>
Furthermore in the last version of Razor you can use tag helpers and you can write back-end code by using special HTML tags.
For example:
@Html.TextBoxFor(m=>m.FirstName, new { @class = "form-control", placeholder=”add a first name”})
Would be:
<input asp-for="FirstName" placeholder=”add a first name” class="form-control" />
Popular in Discussions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance











