Use your own functions

You can also make calls to your own functions.

Add the following link in views\notsimplehello.dt

html
  head
    title Demo site
  body
    header
      h2 Welcome to our not so simple site
    nav
      ul
        li <a href="/">Home</a>
        li <a href="/about">About us</a>
        li <a href="/events">Events</a>
        li <a href="/contact">Contact us</a>
       li <a href="/helloagain">Hello again!</a>
    article
      hl Welcome to our not so simple site!
      div.
        Lorem ipsum dolor sit amet, consectetur adipisci elit, sed
        eiusmod tempor incidunt ut labore et dolore magna aliqua.
        Ut enim ad minim veniam, quis nostrum exercitationem ullam
        corporis suscipit laboriosam, nisi ut aliquid ex ea commodi
        consequatur. Quis aute iure reprehenderit in voluptate velit
        esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
        obcaecat cupiditat non proident, sunt in culpa qui officia
        deserunt mollit anim id est laborum.
    footer
      p Copyright 2023 Notsosimple Company

and edit source\app.d to call your own user-created function helloAgain()

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("*", serveStaticFiles("public/"));
  router.get("/", staticTemplate!"notsimplehello.dt");
  router.get("/about", staticTemplate!"about.dt");
  router.get("/contact", staticTemplate!"contact.dt");
  router.get("/events", staticTemplate!"events.dt");
  router.get("/helloagain",&helloAgain);
  auto listener = listenHTTP(settings, router);
  scope (exit) listener.stopListening();
  runApplication();
}
void helloAgain(HTTPServerRequest req, HTTPServerResponse res)
{
  res.writeBody("Hello again, World!");
}

Compile and run then refresh your browser to localhost:8080/ and click on the Hello again! link and you will see that the new function gets called

Last updated