Vibe.d tutorial
  • Build web apps with Vibe.d
  • Setting up
  • The default hello world app
  • Use your own HTML page
  • Serving other static files
  • Diet templates
  • More template pages
  • Use your own functions
  • Templates for ease of maintenance
  • Using include in templates
  • Responsive layout using CSS Grid
  • A fixed navbar and sticky footer
  • CSS modal dialogues
  • The web interface
  • Setting up MySQL server and tools
  • The schema
  • Setting up MySQL for Vibe.d
  • The EmployeeController class
  • The EmployeeModel class
  • A form for adding a new employee
  • Saving form data into the database
  • Testing the whole thing
  • Listing all the employees
  • Retrieving a record for editing
  • Saving form changes to the database
  • Deleting a record from the database
  • Finding an employee record by name
  • Displaying error messages with _error
  • Authentication and authorization
  • Logging in and authentication
  • Saving the login state to the session
  • Enforcing authorization through the session
  • Logging out
  • All the sources so far
  • A new project
    • The timekeeping system
Powered by GitBook
On this page

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

PreviousMore template pagesNextTemplates for ease of maintenance

Last updated 2 years ago