0# htmltemplate
2A tiny html template 'engine'. It currently supports:
4- replacements of values. Via numbered or not-numbered parameters
5- loops inside the template file
7### Example
9If you want an example with more explainations, consult `examples/02_with_comments.jai`.
11If you want to know what you else can do with the template syntax,
12look at the unit tests & comments in `test/test.jai`.
15HTML template:
16```html
17<div>
18 <p>{{ :foo1: }}</p>
20 {{ :foo2: <a href="%" %>%</a> }}
22 {{ :foo3: <a href="#%1" target="%2">%1</a> }}
24 <ul>
25{{ loop:foo4: <li><a href="#%1">%1</a>%2</li> }}
26 </ul>
27</div>
28```
30Code:
31```text
32#import "Basic";
33#import "htmltemplate";
36main :: () {
37 queue_action: [..]Action;
38 defer array_free(queue_action);
40 commit("foo1", "My Title");
41 commit("foo2", "#about", "target=\"_self\"", "About");
42 commit("foo3", "blog", "_self");
43 commit("foo4", .[
44 .["Foo", "Bar"],
45 .["Fizz", "Buzz"],
46 .["contact", ""],
47 ]);
49 success,
50 html_string,
51 exit_code,
52 error_message := generate(queue_action, TEMPLATE, .STRING);
54 defer {
55 free(html_string);
56 free(error_message);
57 }
59 if !success {
60 log("%", error_message);
61 return;
62 }
64 log("%", html_string);
65}
66```
68Output:
69```html
70<div>
71 <p>My Title</p>
73 <a href="#about" target="_self">About</a>
75 <a href="#blog" target="_self">blog</a>
77 <ul>
78<li><a href="#Foo">Foo</a>Bar</li>
79<li><a href="#Fizz">Fizz</a>Buzz</li>
80<li><a href="#contact">contact</a></li>
81 </ul>
82</div>
83```
86## Compiler Version
88```
89$ jai -version
90Version: beta 0.2.028, built on 9 April 2026.
91```
94## Usage
95Put the library into your project-local `modules` dir,
96or where ever you defined your library path.
99## Tests
100You can run unit tests with: `jai build.jai - run silent`.
103## BNF
105```
106statement = "{{" ( replace | loop ) "}}" ;
108replace = ":" identifier ":" ( html_code )? ;
109loop = "loop" ":" identifier ":" html_code ;
111html_code = { UNICODE | replace_marks | escape_marks } ;
112replace_marks = "%" | "%" number ;
114escape_marks = "\%" ;
115identifier = UNICODE ;
116number = [1-9] ;
117```
index : htmltemplate
---