Using include in templates

Oftentimes we need to break up our layout into smaller parts so that we can just include those smaller parts to compose a page. The include directive is just for that purpose.

Create views\header.dt and extract from views\mainlayout.dt this line:

h2 Welcome to our not so simple site

Then create views\navbar.dt and extract from views\mainlayout.dt this content:

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>

Then create views\footer.dt and extract from views\mainlayout.dt this line:

p Copyright 2022 Notsosimple Company

So what's left with views\mainlayout.dt is this:

html
  head
    title Demo site
  body
    header
      include header.dt
    nav
      include navbar.dt
    article
      block content
    footer
      include footer.dt

Compile, run and refresh the browser. If you see no changes, you did good again.

Last updated