libtemplate — A powerful HTML template library

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.

Example

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;
     }
    

SourceForge Logo
Valid XHTML 1.0! Valid CSS!

Christian Kruse
Last modified: Wed Oct 9 15:09:34 CEST 2002