How to make a page skeletton?

◄ How does a page's source code look?

The same header for all your pages

When your site will grow, you will have several different services for pages which will often contain the same header informations.

A great solutions to avoid code copy-pasting of these recurrent informations are to make a page skeletton function:

let skeletton body_content =
  Lwt.return
    (html
       (head (title (pcdata "Page Title")) [])
       (body body_content)))

So when you define your pages, you just call this skeletton with the content of the page as an argument:

Example.register ~service:main
    (fun () () -> skeletton [p [pcdata "Hello World!"]])

This method can also be adapted to add elements on all your pages, like a header, a footer and a menu. The following example is more complete.

Download full code

◄ Back to the Quick Howto's