1

我将 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.

但我不能在其中渲染“_user_menu.html”,live.html.heex因为(当然)它使用@current_user.

是否有一个技巧可以让我以某种方式在标题的左侧浮动和浮动右侧的“_user_menu.html”片段上拥有实时内容?

4

0 回答 0