Phoenix templates, if conditional

Im migrating from the rails, and expected this to work, in my template?

<% if true do %> <li><p>hello</p></li> <% else %> <li><p>world</p></li> <% end %> 

None of the conditions seem to be displayed. How to achieve this?

thanks

+9
phoenix-framework
source share
1 answer

You need to use <%= instead of <%

 <%= if true do %> ... <% end %> 

From EEx docs :

All expressions that output something to the template must use the equal sign (=). Since everything in Elixir is an expression, there are no exceptions to this rule. For example, while some template languages ​​will have a special case, if sentences, they are processed the same way in EEx, and also require = for their result to be printed:

+20
source share

All Articles