XOOPS.org running Smarty template engine
Date 2002/8/23 0:04:25 | Topic: Developer News
| We 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"> | 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 ' '; }
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} 100%" border="0" cellspacing="0" cellpadding="2"> #E2DBD3"> <b><font color="#666600">{$block.title}font>b> td> tr> <tr> <td valign="top">{$block.content}td> tr> table> <br> {/foreach} td> {/if} tr> table> td> tr> <tr> <td height="30" valign="middle" bgcolor="#DDE1DE" align="center"> {$xoops_footer} td> tr> table> body> html>
Now as you may have noticed, Smarty does not attempt to completely separate logic from the templates. There do exist some Smarty's proprietary logical functions and parameters within template files. However, that is almost ignorable compared to the amount of PHP codes we had in our old theme files, and also there is already a detailed manual on how to use them which you could see at http://smarty.php.net/.
Not only theme files, but each module can have its own template files. We have already converted the forums module running on this site. Though not 100% required, it is highly recommended that all modules use templates, and we will be publishing a detailed doc on how to create template files for a module.
The bad news is that modules utilizing template files will not work under old themes...which also means that all themes should be converted to use Smarty template files.
That's it for now, please report bugs as usual so that we can have the next release as soon as possible.
| |
This article comes from XOOPS Web Application System
https://xoops.org
The URL for this story is:
https://xoops.org/modules/news/article.php?storyid=398