aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanny van Kooten <dannyvankooten@users.noreply.github.com>2020-12-04 10:00:07 +0100
committerDanny van Kooten <dannyvankooten@users.noreply.github.com>2020-12-04 10:01:13 +0100
commita986818ad798d50f41d9e1fd569c926a67341b6e (patch)
tree1413cd0dbc526694948f7f21ff7bc874b6058e44
parent29f2bca03e29bf1f1616b5b9033a1fe510d0d4fe (diff)
downloadunja-master.tar.gz
unja-master.zip
add a more detailed example to READMEHEADmaster
-rw-r--r--README.md47
1 files changed, 39 insertions, 8 deletions
diff --git a/README.md b/README.md
index 9d374d6..05e6056 100644
--- a/README.md
+++ b/README.md
@@ -4,24 +4,55 @@ Unja [![Build Status](https://img.shields.io/travis/dannyvankooten/unja/master)
A template engine for C, inspired by Jinja and Liquid.
-**This is nowhere near being stable right now!**
-
### Example
+File `base.tmpl`:
+```html+jinja
+<html>
+ <head><title>{% block title %}Default title{% endblock %}</title></head>
+ <body>
+ {% block content %}
+ {% endblock %}
+ </body>
+</html>
+```
+
+File `child.tmpl`:
```html+jinja
{% extends "base.html" %}
-{% block title %}Members{% endblock %}
+{% block title %}Users{% endblock %}
{% block content %}
- <ul>
- {% for user in users %}
- <li><a href="{{ user.url }}">{{ user.username }}</a></li>
- {% endfor %}
- </ul>
+ <ul>
+ {% for user in users %}
+ <li><a href="{{ user.url }}">{{ user.username | lower }}</a></li>
+ {% endfor %}
+ </ul>
{% endblock %}
```
+File: `example.c`
+```c
+int main() {
+ // parse all templates in the given directory
+ struct env *env = env_new("./");
+
+ // create a hashmap for storing template variables
+ struct hashmap *vars = hashmap_new();
+ hashmap_insert(vars, "name", "John Doe");
+
+ // execute the template
+ char *output = template(env, "child.tmpl", vars);
+ printf("%s", output);
+
+ // clean-up allocated memory
+ free(output);
+ hashmap_free(vars);
+ env_free(env);
+}
+```
+
### License
MIT \ No newline at end of file