gpt4 book ai didi

phoenix-framework - Phoenix 模板(如果有条件)

转载 作者:行者123 更新时间:2023-12-04 00:34:48 29 4
gpt4 key购买 nike

我从 Rails 迁移,并希望这能在我的模板中工作?

      <% if true do %>
<li><p>hello</p></li>
<% else %>
<li><p>world</p></li>
<% end %>

似乎没有一个条件得到呈现。如何实现这一目标?

谢谢

最佳答案

您需要使用 <%=而不是 <%

<%= if true do %>
...
<% end %>

来自 EEx 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:

关于phoenix-framework - Phoenix 模板(如果有条件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36932002/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com