I’m wondering if someone can tell me which would be more performant inside Phoenix Views/Templates. I’m using Slime as my template engine because I find the syntax a lot easier to read and work with than HTML because it’s concise and has a lot of white space.
In my templates there are several places where the generated text/html is based on options the user has selected. Basically, it’s a multi-step form. To keep my Templates clean I call a function in the View that has a case statement to determine which HTML to send back.
In my Template.html.slimeex
In my View.ex
def option_a_or_b(foo) do case foo do "option A" -> raw('<h1>This is option A</h1>') "option B" -> raw('<h2>This is option B</h2>') end end
So in my function I am returning HTML to the Slime template. Would it be more performant to instead return Slime? Is it even possible to return Slime syntax (I’m actually not sure and can’t find this answer either).
It appears to work fine this way, I’m just curious how the internals work of Template Engines and what is a better practice.