Creating your first template
Templates allow us to define placeholders for dynamic content that can be replaced with the values at runtime by a template engine. They can then be transformed into an HTML file and sent to the client. Creating templates in Go is fairly easy using Go's html/template package, which we will be covering in this recipe.
How to do it…
In this recipe, we are going to create a first-template.html with a couple of placeholders whose value will be injected by the template engine at runtime. Perform the following steps:
- Create
first-template.htmlinside thetemplatesdirectory by executing the following Unix command:
$ mkdir templates && cd templates && touch first-template.html
- Copy the following content to
first-template.html:
<html>
<head>
<meta charset="utf-8">
<title>First Template</title>
<link rel="stylesheet" href="/static/stylesheets/main.css">
</head>
<body>
<h1>Hello {{.Name...