我正在研究凤凰应用程序。身份验证部分使用Guardian
.
与典型的网站一样,该应用程序具有页眉、页脚和侧边栏。这些是布局文件夹中的静态页面。
树视图
-lib
|--admin_app_web
|--templates
|--layouts
|--app.html.eex
|--header.html.eex
|--sidebar.html.eex
|--main.html.eex
app.html.eex
看起来像这样
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
</head>
<body>
<%= render "header.html", conn: @conn%>
<%= render "flash.html", conn: @conn%>
<%= render "main.html", assigns %>
<%=# render "footer.html" %>
<script src="<%= static_path(@conn, "/js/app.js") %>"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>
</body>
</html>
main.html.eex
在这些线上
<main role="main" class="row my-3">
<div class="col-2">
<%= render "sidebar.html" %>
</div>
<div class="col">
<%= render @view_module, @view_template, assigns %>
</div>
</main>
我想渲染sidebar.html.eex
唯一的如果user
是authenticated
,如何实现这一点?