From 9acb03e669e20180b9bc95ca02b21460761fef87 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sun, 3 Jul 2016 03:25:12 +0200 Subject: template-parser: renderer: implemented 'else' support in templates yeah, this is stupid. after more than 320 commits and 26 releases, we finally support the 'else' statement in the template engine. I don't know if I'm dumb or what, but it took me that long to find a "simple" solution to this basic issue. yep, no more `{% ifdef FOO %}...{% endif %}{% ifndef FOO %}...{% endif %}` blocks. but seriously, who cares?! :/ --- man/blogc-template.7.ronn | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'man') diff --git a/man/blogc-template.7.ronn b/man/blogc-template.7.ronn index 3499d7c..1fdc479 100644 --- a/man/blogc-template.7.ronn +++ b/man/blogc-template.7.ronn @@ -143,7 +143,8 @@ based on the value and existence of variables in the current scope. The implementation of conditionals is simple, and each will just evaluate the value of a single variable. -The available conditionals are: `ifdef`, `ifndef` and `if`. +The available conditionals are: `ifdef`, `ifndef` and `if`. `else` statements +are supported. ### ifdef conditional @@ -154,9 +155,12 @@ This is how an `ifdef` conditional is defined in a template: {% ifdef TITLE %} This is title: {{ TITLE }} + {% else %} + Untitled entry {% endif %} -In this case, if the `TITLE` variable is defined, the content is included. +In this case, if the `TITLE` variable is defined, the content after the statement +is included. Otherwise, the content after `else` statement is included. ### ifndef conditional @@ -170,6 +174,8 @@ This is how an `ifndef` conditional is defined in a template: {% endif %} In this case, if the `TITLE` variable is not defined, the content is included. +`else` statements are supported here, even if it does not makes much sense to +be used this way. ### if conditional @@ -184,7 +190,9 @@ comparisions are strcmp(3)-like. This is how an `if` conditional is defined in a template: {% if TITLE == "My Title" %} - Title is "My Title" + Special description of "My Title" + {% else %} + Title is {{ TITLE }} {% endif %} Or: -- cgit v1.2.3-18-g5258