我有一个ejs模板,应该在页面加载时通过调用他们的名字来问候用户,但它不会显示任何内容!这是我的模板:
<!DOCTYPE html>
<html>
<head>
<title>quotes</title>
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">;
<link rel="stylesheet" type="text/css" href="stylesheets/profile.css">
</head>
<body>
<div class="wrapper">
<h1 class="title">profile</h1>
<nav class="nav-bar">
<ul class="nav-list">
<li><a href="/">home</a></li>
<li><a href="/logout">logout</a></li>
</ul>
</nav>
// not displaying user here
<h1 class="greeting">Welcome <% user %></h1>
<form action="/quotes" method="POST" class="new-entry" autocomplete="off">
<h2 class="subtitle">Add a quote</h2>
<input type="text" placeholder="quote" name="quote" pattern=".{3,}" required oninvalid="this.setCustomValidity('3 characters minimum')">
<input type="text" placeholder="author" name="author" pattern=".{1,}" required oninvalid="this.setCustomValidity('1 characters minimum')">
<button type="submit" class="red-button">Add</button>
</form>
<footer>
© 2017
</footer>
</div>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>;
<script src="javascripts/main.js"></script>
</body>
</html>
答案 0 :(得分:1)
您使用的是无效的ejs语法。假设代码在后端正确编写,则需要在开始ejs标记中添加等号,否则模板不知道读取变量的内容。
<%= user %>
应该为您提供所需的结果。
您可以在此处找到有关正确的ejs语法的更多信息:http://ejs.co/