in need of a new template system for some testing and developing we replaced our own template functions with Clearsilver technology. Its awesome
, we stripped down our code about 30-50%, made it more clearer and easier to understand, to program or just to edit the templates.We wrote down all the important config values in a hdf file, makes it so easy to edit (no php or sql knowledge needed) like:
DBASE {
HOST = localhost
USER = cms
PASS = lala
}
SYSTEM
{
SERVERPATH = /usr/local
URL = http://
ADMIN = admin@boy...
}
PAGE {
CONTENT {
INDEX {
NAME = Indexpage
AUTH = Restricted
TEMP = /usr/local/cs/index.cs
}
}
}
Code example with loops, after pushing the "News" in our virtual HDF-File.
<?cs set:count = #1 ?>
<?cs each:item = NEWS ?>
<?cs if:count % #2 ?>
<div style="float:right; padding-left:15px; margin-left: 15px; margin-top: 0; margin-bottom: 10px; width: 240px; border-left: #ccc 1px solid;">
<h2 style="margin-top:0; padding-top:7px;"><?cs var:item.Subject ?> - <?cs var:item.Date ?></h2>
<?cs else?>
<h2><?cs var:item.Subject ?> - <?cs var:item.Date ?></h2>
<?cs /if?>
<p><?cs var:item.Intro ?> <a href="<?cs var:SYSTEM.URL?>/news.fcgi?nid=news.fcgi?<?cs var:item.Id ?>"><?cs var:LANG.MORE ?></a>
<br /><em><?cs var:item.Autor ?></em></p>
<?cs if:count % #2 ?>
</div>
<?cs /if ?>
<?cs set:count = count + #1 ?>
<?cs /each ?>
We were never a fan of XML/XSLT or something like that, so we are very pleased with Clearsilver. Its also used down there at the new Google Groups V2.
A simple other example would be this
<?cs if:USER.LOGGED_IN==1 ?>
show this in language <?cs var:LANG.PROFILE.WELCOME ?>
<?cs else>
show this in language <?cs var:LANG.PROFILE.PLEASE_LOGIN ?>
<?cs /if?>
show all ;=)
A really good (but quite not so known) template system, could be a really big plus for the next version.
You should take a look at http://www.clearsilver.net - the php module/function is currently in development, see this here: http://www.geodata.soton.ac.uk/software/php_clearsilver/
Greetings, Jay
« Last edit by Joerg on Tue May 03, 2005 1:49 pm. »


