When A Classic CMS Is Just Too Much
There are many great content management systems on the Internet that are free and handle a specific task. Pligg we’ve already stated is great for digg clones and Drupal is great for a general purpose website or e-commerce solution. The big blogging management comes directly from wordpress and their awesome CMS.
Not everyone needs these great content management systems or they’ve got a different direction to go. For instance, a site like pownce is a specialized site that I highly respect because of its simple yet clean design.
What do you do when you just want something simple, yet extensible? Or, perhaps you just want to expand your skills and learn some new stuff without having to use a “crutch” like a full CMS.
The answer is a two pronged attack using Template Lite and EZ SQL. Say what?
We’ll call them “libraries” because they’re not a content management system, although they can be used to build your own content management system. As a matter of fact, Pligg uses them as the core for their design as well and they scale well for larger sites.
Template Lite
Are you a php developer that does things like this:
print “<div class=\”images\”><img src=\”src/image01.jpg\”></div>\n”;
If you find yourself printing out HTML in your PHP you’re the audience that needs to be enlighted by template lite. Template lite allows a talented PHP developer to bridge the gap between design and code. If you find yourself writing HTML inside your PHP you’ll soon learn it doesn’t scale very well.
What do you do when you have a missing end DIV tag in your page? You’ll be doing “view source” on your browser and scanning the PHP to fix the issue. Now, you risk making a change and breaking the PHP all together by missing a quote or a semicolon. Rule #1: Avoid mixing PHP and HTML when possible. This also goes for those that believe its tricky (fun?) to write javascript generation inside of PHP.
Writing one language inside another is about as fun as a blister. Sure, it doesn’t look pretty but the more you walk on it the more it hurts.
Template lite allows you to write a full web page without mixing a lot of PHP into the design, allowing for a clean design full of HTML tags and very little php logical blocks or ugly print calls.
A good example, let’s say we want a single input form line to enter a username for a registration screen:
print ‘<input class=“input” type=“password” name=“password” maxlength=“64″ size=“25″ tabindex=“2″ id=“password” value=“‘ . $name . ‘”>\n’;
It works okay for a few lines of PHP, but when you design a full form this way things may get ugly quick. And, when you want to change the tabindex, maxlength or name you’ll be trolling through a large quantity of PHP (you’re designer may hate you). There are many ways of doing PHP string manipulation, the example above concatenates three strings together (the base, the name and the ending) and then displays it.
However, a template looks a bit more like HTML:
<input class=“input” type=“password” name=“password” maxlength=“64″ size=“25″ tabindex=“2″ id=“password” value=“{$name}”>
It’s all basic HTML with the exception of {$name} inside the value string. A designer doesn’t get all up in arms with a “{$name}” variable in their HTML and it’s much simpler than embedding PHP into a print or echo string. The designer can how have the option to move around key values like {$name} to where ever they want! Now, let’s pretend they also wanted to say hi to the user:
<span class=”welcome_message”>Hi, {$name}</span>
Without having to understand PHP they’ve become a programmer in the matter of seconds! You simply supply them with a set of variables and they can wrap HTML around it all day long. Or, in some cases, you’re a developer and a designer and you want to do both. Now, you can segment your work into two separate designs and work them independently.
Put on your developer hat and do some code and worry about designing it for the user experience later. But, now does the developer work with template lite?
Template lite is a PHP object with all the goodies hidden simplicity. You learn some basic options and you’re ready to rumble:
$tpl = new Template_Lite; // Create template object
$username = “test user”; // Test user account
$tpl->compile_dir = “compiled/”;
$tpl->template_dir = “templates/”;
$tpl->assign( “user”, $username );
$tpl->display( “admin.tpl” ); // Display some pre-created template file
On the PHP side, we create a variable out of the template lite object called $tpl and assign the directory where we store our templates (this is part of the template lite documentation which is well supported). We bind our “variables” with our PHP variables using the ‘assign’ function which makes “user” (or, {$user} in the template) have the value of $username which we defined as “test user”.
This is the key to abstracting design content with php development. You don’t have to be writing a world class application to find a need for such abstraction! It cuts the complexity of your code down, removes HTML from being bound into your sources and allows you to design a rich HTML interface without being harassed by php logic and escaping quotes.
Most importantly, you’ll find a drastic reduction of stupid bugs when you stop coding two languages inside one another (yes, HTML is kind of a language).
EZ SQL
When designing complex PHP applications you’ll find yourself in need of a database almost immediately. Providing you already have some SQL knowledge (or know where to find some) you’ve got all you need to start doing database transactions.
However, the PHP implementation of database queries is often a bit tedious in how it returns data. Abstracting some of this complexity can be done using EZ SQL. It’s an object oriented approach to solving world hunger… well, it makes PHP and databases a bit easier.
You need a row? The get_row() function returns to you a pretty object with all the data you need. For instance, if you have a database table with fields: username, password and email you can obtain them quickly:
// Connect to the db as db_user with password secret_password and such…
$db = new ezSQL_mysql(’db_user’, ’secret_password’,
‘database_name’, ‘localhost’);$user = $db->get_row( “SELECT username,password,email FROM users WHERE username = ‘fred’” );
print “Your name is: $user->username\n”;
print “Your password is: $user->password\n”;
print “Your email is: $user->email\n”;
This is a clear and pretty way of extracting data from your database, combine it with Template Lite and you’re on the road to making a very quick management system. Why re-design the wheel when there are tools online to get you 40% through your project before you even begin?
Don’t re-build the basic stuff, save all that brain power for designing something new, fresh and creative.

Posted in Design, Development, Template_Lite, EZSQL