Free HTML Template Engine
If you're tired of recompiling your CGI program every time somebody wants to change the HTML, you need to check out templates. Libtemplate is an easy to use C interface that will let you use the same sort of templates used in Lazarus applications.
Using templates in PHP and C++ has spoiled me. So when I started developing applications in C, I went hunting for a templating library that I could use again. I didn't find it, so after developing in a mixture of C for my lowlevel routines and C++ for my interface, I finally broke down and wrote a templating engine in C.
This software is free to use on any web site, commercial or otherwise. You can purchase a technical support contract if you find yourself in need.
Please download the files from the archives below.
| Attachment | Size |
|---|---|
| template-source.zip | 32.36 KB |
| templatizer-c++.tar.gz | 1.84 KB |
| templatizer-php.tar.gz | 1.59 KB |
| template-engine.pdf | 18.15 KB |

![View your cart items []](/sites/all/modules/ecommerce/cart/images/cart_empty.png)

How does you solution compares to
I was doing some research looking for a open-source template engine for C/C++ and I've found your site.
I would like to know how does your project compare to more public projects like: http://teng.sourceforge.net and http://www.clearsilver.net/
I wrote a little about them on my page, take a look, and please notify me about this maybe I'll include yours too.
Comparison
libtemplate is much simpler than either teng or clearsilver. Both of those are implemented as fairly sophisticated engines which provide their own framework for web applications. Teng, for instance, allows embedding display logic into templates.
libtemplate has a very simple and direct focus. It's sole purpose is to replace named element tags with values from the program. Because the result of a Parse operation is another named element, very flexible output can still be achieved without embedding text or html in the program.
I chose this option so that the templates would be extremely simple. With a minimal amount of training anyone capable of writing HTML can write a template. If more complex logic is needed in the output than what static HTML can handle, the programmer will implement it in C (or whatever language they're using). Making the templates more complex seemed like reinventing the wheel to me.
--
Clay Dowling
President
Lazarus Internet Development
Test for C/C++
where is the test.c which is mentioned in template-engine.pdf
i would like to see a practical c/c++ example on how to use the template engine
Test sample
i found this: http://www.wxjavascript.net/tpl/index.html and usage is the same
Test cde converted to C
// Insert leading spaces/tabs to suit your requirements.
// ----------------------------------------
// test.c
#include
#include "template.h"
#define true 1
#define false 0
int
main(void)
{
struct tpl_engine *engine;
int n;
char n1[10],n2[10], n3[10];
engine = tpl_engine_new();
// Load the template file
tpl_file_load(engine, "test.tpl");
for(n = 1;n <= 10; n++)
{
sprintf(n1, "%d", n);
sprintf(n2, "%d", n*n);
sprintf(n3, "%d", n*n*n);
tpl_element_set(engine, "n", n1);
tpl_element_set(engine, "n2", n2);
tpl_element_set(engine, "n3", n3);
// Parse the template 'row' and add the result to element 'rows'
tpl_parse(engine, "row", "rows", true);
}
tpl_parse(engine, "grid", "main", false);
printf("%s", tpl_element_get(engine, "main"));
return 0;
} // main
// ----------------------------------------
//test.tpl
<template name="grid">
<table>
<tr>
<th>n</th>
<th>nˆ2</th>
<th>nˆ3</th>
</tr>
{rows}
</table>
</template>
<template name="row">
<tr>
<td>{n}</td>
<td>{n2}</td>
<td>{n3}</td>
</tr>
</template>
// ----------------------------------------
// compiler instructions for gcc
gcc -Wall -o template.o template.c
gcc -Wall -o test template.o test.c
// ----------------------------------------