Litwicki Media
  • Hire UsFREE Estimate!
  • Our WorkPortfolio of Work
  • ServicesWhat We Do
  • NotebookCompany Blog
  • DashboardMy Projects
  • Latest

    • Dashboard WYSIWYG
    • Switch to SMARTY from phpBB TEMPLATE Class
    • Litwicki Dashboard – Flexibility is Essential!
    • Working Title: Litwicki-Dashboard
    • Best Practices – Defining tables & writing SQL
  • Categories

    • Best Practices (2)
    • CSS (1)
    • Default (8)
    • HTML/XHTML (3)
    • Linux (1)
    • PHP (5)
    • Products (3)
    • Servers (1)
    • SQL (1)
    • Standards (2)
    • SVN (1)
    • Thoughts (2)
  • History

    • May 2010 (1)
    • April 2010 (3)
    • March 2010 (7)

Switch to SMARTY from phpBB TEMPLATE Class

Our clients, and our work in general make using the GNU GPLv3 very difficult. For this reason, you may find yourself in a situation where you would like to use a more commercial friendly template engine. Rewriting your template code, and your PHP is not as complex as you might think:

Before: XHTML

<!-- BEGIN user_row -->
{user_row.user_id} - {user_row.username}
<!-- END user_row -->

Before: PHP

while( $row = mysql_fetch_row($result) )
{
$template->assign_block_vars('user_row', array(
'user_id' => $row['user_id'],
'username' => $row['username'],
));
}

After: XHTML

{section name=user loop=$user_row}
{$user_row[user].user_id} - {$user_row[user].username}
{/section}

After: PHP

while( $row = mysql_fetch_row($result) )
{
$user = array(
'user_id' => $row['user_id'],
'username' => $row['username'],
);
$user_rows[] = $user;
}
$template->assign(array, $user_rows);

There are other ways to assign your arrays for SMARTY, but I prefer a more human readable approach that shows a linear assignment from database, to loop array, to template array.

Continue reading » · Rating: · Written on: 04-15-10 · 1 Comment »

Copyright © 2009 Litwicki Media LLC. Powered by Wordpress with the Litwicki Media theme.

Litwicki Media is a small website design & development studio. We make stunning websites with higher standards by raising the bar, without raising the cost. We have built websites for companies like Wal-Mart Realty, JD Power & Associates, Nestle USA, Acquisola, and dozens more!

  • HIRE US - FREE Estimate
  • Our Work
  • Services
  • Contact
  • About