我将 root.html.heex 文件更改为如下所示:
<!DOCTYPE html>
<html lang="en">
<head>
...
</head>
<body>
<%= @inner_content %>
</body>
</html>
并移动了<header>
要在 app.html.heex
中复制的元素:
<header>
<section class="container w-full m-5 p-3 bg-blue-200 text-blue-600 text-5xl font-bold">
<div class="text-2xl">
<a href="/">
<img class="float-left mt-1"
src={Routes.static_path(@conn, "/images/logo.png")} alt="LOGO"/>
<span class="flex text-4xl hover:text-blue-800">
<span class="font-medium nomargin">WEBSITE</span>
</span>
</a>
<span class="float-right flex -mt-8 font-normal">
<nav role="navigation">
<%= render "_user_menu.html", assigns %>
</nav>
</span>
</div>
</section>
</header>
<main class="container">
<p class="alert alert-info" role="alert"><%= get_flash(@conn, :info) %></p>
<p class="alert alert-danger" role="alert"><%= get_flash(@conn, :error) %></p>
<%= @inner_content %>
</main>
...并在 live.html.heex
中.
但我无法在 live.html.heex
中呈现“_user_menu.html”因为(当然)它使用 @current_user
.
有没有什么技巧可以让我在标题的 float 左侧有实时内容,在 float 右侧有“_user_menu.html”片段?
最佳答案
通常,如果您需要混合“Live”和“Dead” View /模板,可以使用 live_render/3
documented here .去过那里,看到 [工作] ;-)
关于http-headers - 如何在我的 Elixir Phoenix LiveView 应用标题中混合实时内容和 "dead"内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70919996/