Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elixir Phoenix flash messages do not show up

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?

like image 469
Pratik Khadloya Avatar asked Dec 03 '15 14:12

Pratik Khadloya


1 Answers

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:

like image 190
Gazler Avatar answered Oct 21 '22 00:10

Gazler