diff options
-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 |