Elixir Phoenix Flash Messages Not Displaying

I am trying to display flash messages in a Phoenix app, but they do not seem to be displayed. I tried many different things, one of them:

<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 someone point me to the correct code?

+4
source share
1 answer

You need to use <%=instead<%

<%= if info do %>
  <div class="alert alert-info" role="alert"><%= info %></div>
<% end %>

From documents :

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 ​​have special if statements, they are handled the same way in EEx, and they also require = to print their result:

+13

Source: https://habr.com/ru/post/1618444/


All Articles