Developer News

XOOPS.org running Smarty template engine

onokazu  23 Aug 2002 12:04 AM 12823 Reads   No comments 
le="color: #000000"><?php function themeheader($show_rblock) { global $xoopsConfig; echo '<body bgcolor="#ffffff">'; OpenWaitBox(); echo '<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 ( $xoopsConfig['banners'] == 1 ) { showbanner(); } echo '</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" align="center">'; make_sidebar("left"); echo '</td> <td align="center" valign="top">'; } function themefooter($show_rblock, $footer) { echo "</td>"; if ( $show_rblock ) { echo '<td width="20%" bgcolor="#efefef" valign="top" align="center">'; make_sidebar("right"); } echo '</td></tr></table></td></tr><tr> <td height="30" valign="middle" bgcolor="#DDE1DE" align="center">'; echo $footer; echo '</td> </tr> </table>'; CloseWaitBox(); } function themesidebox($title, $content) { echo '<table width="100%" border="0" cellspacing="0" cellpadding="2"> <tr> <td bgcolor="#E2DBD3"><b><font color="#666600">'.$title.'</font></b></td> </tr> <tr> <td valign="top">'.$content.'</td> </tr> </table><br>'; }


whereas when we use Smarty, the layout.tpl file which defines the total look of the site will become:

le="color: #000000"><?php <!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'><!-- @import url({$xoops_themecss}); --></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} <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> {/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.
Rating 0/5
Rating: 0/5 (0 votes)
Voting is disabled!


Login

Donat-O-Meter

Stats
Goal: $15.00
Due Date: Jul 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $15.00
Make donations with PayPal!

Categories