The libtemplate is a powerful template engine. It supports embedding variables, if-then-else structures and functions. In future releases it will support for and foreach. You can download it at the Sourceforge.Net Project Site. Any comments are welcome, just send me a mail.
template.html
<$ $IMG_URI = "http://libtemplate.sourceforge.net/pics/"; $BASE_URI = "http://libtemplate.sourceforge.net/"; $TITLE = "Example"; include "siteheader.html"; $> <p> This is the main content. You can do everything you want, even <$ print $action; $>. </p> <$ include "sitefooter.html"; $>
siteheader.html
<html> <head> <title><$ print $TITLE; $></title> </head> <body> <h1><$ print $TITLE; $>
sitefooter.html
<p>Page footer (<$ print $TITLE; $>)</p> </body> </html>
example.c
#include <stdio.h> #include <stdlib.h> #include <libtemplate.h> int main(int argv,char *argc[]) { t_string out; t_template tpl; printf("Content-Type: text/html; charset=iso-8859-1\015\012\015\012"); if(tpl_new_template(&tpl,"template.html") != 0) { printf("Error: %s\n",tpl_error_message(&tpl)); return EXIT_FAILURE; } tpl_setvar(&tpl,"action","printing variables"); if(tpl_evaluate_to_mem(&tpl,&str) != 0) { printf("Error: %s\n",tpl_error_message(&tpl;)); tpl_cleanup(&tpl); if(str.len) str_cleanup(&str); return EXIT_FAILURE; } printf("%s\n",tpl.content); str_cleanup(&tpl); tpl_cleanup(&tpl); return EXIT_SUCCESS; }