I am trying to display flash messages in a Phoenix app, but they don't seem to show up. I have tried many different things, one of them is:
<div class="row">
<div class="col-sm-12">
<%
info = get_flash(@conn, :info)
error = get_flash(@conn, :error)
%>
<% if info do %>
<div class="alert alert-info" role="alert"><%= info %></div>
<% end %>
<% if error do %>
<div class="alert alert-danger" role="alert"><%= error %></div>
<% end %>
</div>
</div>
Can anyone point me to the right code?
You need to use <%=
instead of <%
<%= if info do %>
<div class="alert alert-info" role="alert"><%= info %></div>
<% end %>
From the docs:
All expressions that output something to the template must use the equals sign (=). Since everything in Elixir is an expression, there are no exceptions for this rule. For example, while some template languages would special-case if clauses, they are treated the same in EEx and also require = in order to have their result printed:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With