我正在尝试在Phoenix应用程序中显示Flash消息,但它们似乎没有显示。我尝试了很多不同的东西,其中之一是:
<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>
谁能指出我正确的代码?
最佳答案
您需要使用<%=
而不是<%
<%= if info do %>
<div class="alert alert-info" role="alert"><%= info %></div>
<% end %>
从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:
关于Elixir Phoenix Flash消息不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34068589/