加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Elixir Phoenix flash消息不显示

发布时间:2020-12-15 07:29:30 所属栏目:百科 来源:网络整理
导读:我试图在凤凰应用程序中显示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"
我试图在凤凰应用程序中显示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:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读