From 4624d6d369e8e5ce9a887acfe27be90fedf3d1ed Mon Sep 17 00:00:00 2001 From: Danny van Kooten Date: Tue, 17 Mar 2020 13:55:23 +0100 Subject: add support for {% else %} statements --- src/template.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/template.c b/src/template.c index 1f6a34f..d3765a1 100644 --- a/src/template.c +++ b/src/template.c @@ -231,6 +231,10 @@ int eval(char *dest, mpc_ast_t* t, struct hashmap *ctx) { if (object_is_truthy(result)) { eval(dest, t->children[4], ctx); + } else { + if (t->children_num > 8) { + eval(dest, t->children[8], ctx); + } } object_free(result); @@ -293,8 +297,7 @@ mpc_parser_t *parser_init() { " for : \"for \" \"in\" \"endfor\" ;" " block : \"block \" \"endblock\" ;" " extends : \"extends \" ;" - /* TODO: Extend parser to include expression */ - " if : \"if \" \"endif\" ;" + " if : \"if \" ( \"else\" )? \"endif\" ;" " statement : | | | ;" " content : | | | ;" " body : * ;" -- cgit v1.2.3