jononomo

jononomo

Is there a super-simple phoenix web framework alternative?

I’m wondering if there is an Elixir web framework that is basically just a router and some templates. I’ve noticed that with Phoenix I just feel like I have too many files and one extra layer of indirection through everything.

I don’t quite understand why the templates/ folder is not stored under the views/ folder for instance, since templates are just compiled into those view files, or even why the view files really exist at all – seems like they’re often just empty and play no role other than to follow a naming convention based on the controller.

I think Phoenix is aiming to be powerful enough to drive the most sophisticated current users of Ruby on Rails, but I think there is also a space for those who just want little toy websites, demo apps, examples, etc, and don’t need the extras that Phoenix provides.

Marked As Solved

sodapopcan

sodapopcan

I don’t quite understand why the templates/ folder is not stored under the views/ folder for instance

The purpose of a view is to take in data from a controller and render a template with it with whatever additional presentation logic is required. Rails takes these two concepts and mostly mashes them into one calling them “views”. I say “mostly” because combining these means there is no place to implement presentation logic, so they provide “helpers”.

Ah helpers… the dumping ground of so many rails apps I’ve worked on. And a lot of time presentation logic just ends up in the “view” itself! This is such a problem that such gems as draper and presenter came about. You could kind of think of these gems as the Phoenix’s view and Rails’ views as Phoenix’s templates.

I imagine Rails chose to combine these because a lot of time we don’t need additional presentation logic right of the bat. It also means helpers can be shared between view and controllers (which is of dubious utility). But it’s inevitable that anything more than a toy project is going to need additional presentation logic, so Phoenix points us in the right direction by giving us a proper view → template mechanism, forcing us to create a view even if sometimes we aren’t going to need any presenters.

13
Post #3

Also Liked

LostKobrakai

LostKobrakai

You already got the technical reason: Views hold the compiled functions for rendering those templates. Without the view modules those templates would just be files sitting in your project with no way to use them. So while those view modules may seem empty they for sure don’t stay empty if there are templates for it. That would be more obvious if phoenix wouldn’t hide all the template loading code behind the use MyAppWeb, :view, ….

Also while for html based pages one often uses templates this is not at all the case of e.g. rendering json. There the composition of the output format usually takes place in those view modules directly. Not every format out there lends itself to templating being the prefered method of construction. In phoenix both are cleanly supported by having views be responsible to turn data into some response format, while only the view layer is concerned with the distinction between rendering the format from code or from a template.

delameko

delameko

It’s also worth pointing out that one of the great things about Elixir is you can pretty much move your files anywhere. I gather all my files together by resource, rather than by type, like:

posts/
  post_controller.ex
  post_view.ex
  templates/
    index.html.eex

Moving the templates just requires a change to the view function in MyAppWeb:

use Phoenix.View,
  root: __DIR__,
  path: "templates",
  namespace: MyAppWeb
lpil

lpil

Creator of Gleam

Plug is great, as suggested by cpgo.

If you want simpler still check out Raxx

Last Post!

gabrielpoca

gabrielpoca

If the only thing you need is a router and some templates, I guess a static site generator will do? There’s Still GitHub - still-ex/still: A composable Elixir static site generator · GitHub which is still alpha, but you can throw some files into a folder, compile it and deploy it to S3/Github Pages/Netlify/etc.

Where Next?

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2976 91332 914
New
f0rest8
Hi everyone :waving_hand: Posting here to showcase and announce that Metamorphic is now officially live on a public-facing domain at htt...
New
andrielfn
Hey there :waving_hand: I want to introduce Fluxon UI, a modern UI component library for Phoenix LiveView that I have been working on fo...
New
byu
@chrismccord : I just saw the Extract AGENTS.md from Phoenix.new into phx.new generator commit to the phoenix project. My initial shotgu...
New
arcanemachine
I was working on an Ecto migration and I needed a timestamp. So, for the nth time, I looked up the different data types for timestamps, a...
New
AstonJ
Just a general thread to post chat/news/info relating to AI/ML stuff that may be relevant for Nx now or in the future. Got anything to sh...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
kip
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
webofbits
Squid Mesh is an open source workflow automation runtime for Elixir applications. It is aimed at Phoenix and OTP apps that want to defin...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
kip
In 2021 I started a new library called Tempo with the objective of modelling time as a set of intervals - not as instants. In 2022 I gave...
New

We're in Beta

About us Mission Statement