【发布时间】:2021-10-05 23:13:21
【问题描述】:
在这段代码中,我试图设置导航栏,并在每个文件中定义nav,因为对于某些文件,导航栏将登录或注册,但对于某些文件,它将被注销或注销。除了这个login.html 之外,没有文件给我错误,错误是
错误
panic: template: login.html:7: unexpected <define> in command
代码
{{template "base" .}}
{{define "title"}} Log In {{end}}
{{define "body"}}
{{if .Loggedin}}
{{define "nav"}} // this is line 7 which is showing error.
<div>
<a href="/about">About</a>
<a href="/logout">Logout</a>
</div>
{{end}}
{{else}}
<h1> Log In</h1>
<p>Login to access your account.</p>
<hr>
<form action="/loggedin" method="POST" name="login" id="login">
<div>
<label for="email">Email</label>
<input type="email" name="email", placeholder="Enter your email address" required>
</div>
<div>
<label for="password">Password</label>
<input type="password" name="password", placeholder="Enter the password" required>
</div>
<div>
<input type="submit" value="Login">
</div>
</form>
{{end}}
{{end}}
【问题讨论】:
标签: go go-templates