With N2O you don’t need to use HTML at all. Instead you define your page in the form of Erlang records so that the page is type checked at the compile time. This is a classic CGI approach for compiled pages and it gives us all the benefits of compile time error checking and provides DSL for client and server-side rendering.
The core set of HTML elements includes br, headings, links, tables, lists and image tags. Static elements are transformed into HTML during rendering.
Static elements could also be used as placeholders for other HTML elements. Usually “static” means elements that don’t use postback parameter:
This will produce the following HTML code:
This will produce the following HTML:
If postback action is specified then the page module must include a callback to handle postback info:
Each HTML element in N2O DSL has record compatibility with the base element.
Here module is an Erlang module that contains a render function. Data and Aria HTML custom fields are common attributes for all elements. In case element name doesn’t correspond to HTML tag, html_tag field provided. body field is used as element contents for all elements.
Most HTML elements are defined as basic elements. You can even choose element’s name different from its original HTML tag name:
DTL stands for Django Template Language. A DTL element lets to construct HTML snippet from template with given placeholders for further substitution. Fields contain substitution bindings proplist, filename and templates folder.
You can use templates not only for pages, but for controls as well. Let’s say we want to use DTL iterators for constructing list elements:
Here is an example of how to pass variables to the DTL template we’ve just defined:
bind_script should be set to true for page templates. When control elements are rendered from DTL, bind_script should be set to false.