OCaml-WebFramework /

Filename Size Date modified Message
17 B
89 B
34.3 KB
1.1 KB
2.2 KB


Template engine

The template engine, programmed with OCaml, is designed to process web templates (situated in /templates/) and dynamic content (situated in /cgi-bin) to produce output web documents.

The template language uses the following syntax :

  • [begin *part*]*html code*[end] : defines a part of html code
  • { *part* } : includes the content of the part part previously defined
  • {% *function* %} : includes the result of the OCaml function function. The function must be declared in the file /cgi-bin/
  • {@ *template* @} : Tells the template engine that the current template "extends" another template.

Once template processing is complete, the content of the part base is printed by the CGI.

URL dispatcher

The URL is divided as follows :


arg0 represents the name of the page asked by the user. You can link arg0 to a template in the file /cgi-bin/ The others arguments can be gotten with the function Env.get_url_arg n.



[begin base]
<!DOCTYPE html>
    <title>OCaml-WebFramework -{ title }</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <li><a href="?index/">Home</a></li>
        <li><a href="?about/">About</a></li>
    { body }


{@ base.html @}

[begin title] Index [end]

[begin body]
<h1>Hello World ! </h1>
<p>{% get_time %}</p>


{@ base.html @}

[begin title] About [end]

[begin body]


let get_page_from_url () =
  match Env.get_url_arg 0 with
    | "about" -> "about.html"
    | _ -> "index.html"


let get_function = function
  | "get_time" -> Date.get_date ()
  | f -> "Cannot find function : " ^ f
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.