diff options
author | Danny van Kooten <dannyvankooten@users.noreply.github.com> | 2020-12-04 10:00:07 +0100 |
---|---|---|
committer | Danny van Kooten <dannyvankooten@users.noreply.github.com> | 2020-12-04 10:01:13 +0100 |
commit | a986818ad798d50f41d9e1fd569c926a67341b6e (patch) | |
tree | 1413cd0dbc526694948f7f21ff7bc874b6058e44 | |
parent | 29f2bca03e29bf1f1616b5b9033a1fe510d0d4fe (diff) | |
download | unja-a986818ad798d50f41d9e1fd569c926a67341b6e.tar.gz unja-a986818ad798d50f41d9e1fd569c926a67341b6e.zip |
-rw-r--r-- | README.md | 47 |
1 files changed, 39 insertions, 8 deletions
@@ -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 |