From a986818ad798d50f41d9e1fd569c926a67341b6e Mon Sep 17 00:00:00 2001 From: Danny van Kooten Date: Fri, 4 Dec 2020 10:00:07 +0100 Subject: add a more detailed example to README --- README.md | 47 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 8 deletions(-) (limited to 'README.md') 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 + + {% block title %}Default title{% endblock %} + + {% block content %} + {% endblock %} + + +``` + +File `child.tmpl`: ```html+jinja {% extends "base.html" %} -{% block title %}Members{% endblock %} +{% block title %}Users{% endblock %} {% block content %} - + {% 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 -- cgit v1.2.3