Creating the View Templates
For this functionality, we'll need two new templates:
1. templates/create-article.html
This will display the article creation form using the following code:
<!--create-article.html-->
{{ template "header.html" .}}
<h1>Create Article</h1>
<div class="panel panel-default col-sm-12">
<div class="panel-body">
{{ if .ErrorTitle}}
<p class="bg-danger">
{{.ErrorTitle}}: {{.ErrorMessage}}
</p>
{{end}}
<form class="form" action="/article/create" method="POST">
<div class="form-group">
<label for="title">Username</label>
<input type="text" class="form-control" id="title" name="title" placeholder="Title">
</div>
<div class="form-group">
<label for="content">Password</label>
<textarea name="content" class="form-control" rows="10" id="content" laceholder="Article Content"></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
{{ template "footer.html" .}}
2. templates/submission-successful.html
This will be displayed after a successful article submission.
<!--submission-successful.html-->
{{ template "header.html" .}}
<div>
<strong>The article was successfully submitted.</strong>
<a href="/article/view/{{.payload.ID}}">{{.payload.Title}}</a>
</div>
{{ template "footer.html" .}}
We also need to modify templates/menu.html
to display the Create Article
link, as follows:
<!--menu.html-->
.
.
<ul class="nav navbar-nav">
<li><a href="/article/create">Create Article</a></li>
.
.
</ul>
.
.