Then build and run the project and refresh the browser to see the new message:
We just tested that the new HTML file is working. Now, let’s convert the HTML file into a Diet template file.
Save the views\simplehello.html file as views\simplehello.dt with this contents:
It feels weird at first, but then you realize there is less to type when using Diet templates.
Then edit source\app.d to make it display simplehello.dt instead:
In your terminal, stop the app if it is still running (Ctrl-C), then compile and run.
dub --force
We sometimes use the --force option to tell dub to recompile everything again, just in case it fails to see that some files were changed and needed to be recompiled or that there are updated libraries that needed to be downloaded again.
doctype html
html
head
title Simple hello using a template
body
h1 Simple hello world from a template!
h2 How are you doing today?
| Please visit the home of <a href="https://vibed.org/">Vibe.d</a>
import vibe.vibe;
void main()
{
auto settings = new HTTPServerSettings;
settings.port = 8080;
settings.bindAddresses = ["::1", "127.0.0.1"];
auto router = new URLRouter;
router.get("/",staticTemplate!"simplehello.dt");
router.get("*", serveStaticFiles("public/"));
auto listener = listenHTTP(settings, router);
scope (exit) listener.stopListening();
runApplication();
}