Developer News: XOOPS.org running Smarty template engine
Posted by: onokazuOn 2002/8/23 0:04:25 14093 readsWe have just upgraded our site to the latest development version (CVS + Smarty). We are now using Smarty template engine as the new theme system. Now, what is Smarty, and what would be the benefit for us users and developers?
Quote:
Quoted from http://smarty.php.net/:
Smarty is a template engine for PHP. More specifically, it facilitates a managable way to separate application logic and content from its presentation. This is best described in a situation where the application programmer and the template designer play different roles, or in most cases are not the same person.
In short, with Smarty, designers can have total control over application presentation by just modifying template files, and module developers would only need to concentrate on application logic and passing variables to those template files.
For example, our old 'phpkaox' theme file looked like this:
function themeheader($show_rblock) {
global $xoopsConfig;
echo '';
OpenWaitBox();
echo '
bgcolor="#666666">
.XOOPS_URL.'">
.XOOPS_URL.'/themes/phpkaox/images/logo.gif">
';
if ( $xoopsConfig['banners'] == 1 ) {
showbanner();
}
echo '
cellspacing="0" cellpadding="0" height="100%">
valign="top" align="center">';
make_sidebar("left");
echo '
';
}
function themefooter($show_rblock, $footer) {
echo " ";
if ( $show_rblock ) {
echo '';
make_sidebar("right");
}
echo '
';
echo $footer;
echo '
';
CloseWaitBox();
}
function themesidebox($title, $content) {
echo '
'.$title.'
'.$content.'
';
}
whereas when we use Smarty, the layout.tpl file which defines the total look of the site will become:
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset={$xoops_charset}' />
<meta name='keywords' content='' />
<meta name='description' content='' />
<meta name='generator' content='{$xoops_version}' />
<title>{$xoops_pagetitle}title>
<link rel='stylesheet' type='text/css' media='all' href='{$xoops_url}/xoops.css' />
{if $xoops_themecss != ""}
<style type='text/css' media='all'>style>
{/if}
<link href='{$xoops_url}/favicon.ico' rel='SHORTCUT ICON' />
<script src='{$xoops_url}/include/xoopsjs.php'>script>
head>
<body>
<table width="100%" border="0" cellspacing="1" cellpadding="0" bgcolor="#666666">
<tr>
<td valign="top" bgcolor="#DDE1DE">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="285" valign="middle" align="center">
<a href="{$xoops_url}/">
<img src="{$xoops_url}/themes/phpkaox/images/logo.gif">
a>
td>
<td>
{if $xoops_banner != ""}
{$xoops_banner}
{else}
{/if}
td>
tr>
table>
td>
tr>
<tr>
<td valign="top" bgcolor="#FFFFFF">
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
<tr>
<td width="20%" bgcolor="#EFEFEF" valign="top">
{foreach item=block from=$xoops_lblocks}
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr>
<td bgcolor="#E2DBD3">
<b><font color="#666600">{$block.title}font>b>
td>
tr>
<tr>
<td valign="top">{$block.content}td>
tr>
table>
<br>
{/foreach}
td>
<td valign="top">
{if $xoops_contents_tpl == ""}
{$xoops_contents}
{else}
{include file="$xoops_contents_tpldir/$xoops_contents_tpl"}
{/if}
td>
{if $xoops_showrblock == 1}
<td width="20%" bgcolor="#efefef" valign="top">";
{foreach item=block from=$xoops_rblocks}