Ericson Smith

Conditionally render templates in Phoenix - Elixir

3 years ago

Sometimes in a Phoenix Framework project, you want to conditionally render a template. Why not just use a "cond" or "case" or a bunch of "if" statements?

Well, i'm lazy, is the short answer.

But the long answer is that i want to just add new templates, which is just like adding new functionality. And if I don't have that functionality, I just drop back to a default EEX template.

The handy "render_existing" function handles this very well, but it's not so obvious in the documentation.

And there you have it. Simple conditional template rendering in Phoenix Framework.

 

MORE LIKE THIS

© 2024 Ericson C. Smith

About me | Writings | Projects | Contact | X