The Template Engine Hype? Which one?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
josamoto
Forum Commoner
Posts: 41
Joined: Fri Aug 24, 2007 6:57 am
Location: South Africa
Contact:

The Template Engine Hype? Which one?

Post by josamoto »

There are many template engines / frameworks for PHP out there. To name a few:

- Zend Framework - http://framework.zend.com
- Code Ignigter - http://www.codeignigter.com
- Cake PHP - http://www.cakephp.org
- Smarty -http://smarty.php.net
- PEAR - http://pear.php.net

and I believe many more.

Which are the most popular / best to use, being both lightweight and easy to learn? I understand that much of it comes down to your own preference, but in generally speaking I'd like some opinions on which one to use, as I feel overwhelmed by the amount of engines available.

Is there an online comparison on the different frameworks?
Last edited by josamoto on Mon Sep 10, 2007 4:26 am, edited 1 time in total.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Those things are all a little different. Zend, Cake and Code Igniter are frameworks -- some with class libraries. Smarty is a template library. PEAR is a class library that contains several template libraries and many other classes.

What are you looking for?
(#10850)
User avatar
josamoto
Forum Commoner
Posts: 41
Joined: Fri Aug 24, 2007 6:57 am
Location: South Africa
Contact:

Post by josamoto »

I need a MVC sort of thing, but not something with a million-and-one classes. Also looking at the URL parsing abilities of CodeIgniter, as well as functions for making my everyday tasks in PHP easier and have development go much quicker. CodeIgniter has shorthand tags for PHP for example you can use <:=funkyChicken?>. I basically want JSP custom tags, but in PHP.

My main interest is in separating my application logic from my template / user-interface, i.e. MVC (Model + View + Controller). A lot of the code we develop gets reused a lot, as we develop websites for estate agents. Currently all 300 sites have a copy of it's own application logic. So if a bug appears, we have to fix it in 300 instances of code.

I want to revamp the code so its all central with also a central database, but each agent has their own website template, which draws information related to their site from the central database using centralized code. One instance of code will make the project easier and allow us to create a portal as well as maintain the code, supply bug fixes and develop add-ons across the board. Also one database is used across multiple agents where their data is separated by means of a unique agent ID.

Basically I need a RAD strategy, and at current, CodeIgniter looks the best for me. PEAR and Zend Framework are too expansive, I do suppose it has been around for a while so more code has been developed.
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

This is what I use, very simple way to separate logic and no added baggage. Essentially you will create a 'templates' folder, then you will have two pages, for example index.php will have a corresponding templates/index-tpl.php, all display logic gets put into the template, and business into the index.php.

Code: Select all

<?
/**
 * set() - sets a variable to be used in the template
 * display() - includes the template file (FILENAME-tpl.php)
 */

class templates{
	
	function set($name, $value){

		$this->vars[$name] = $value;
	}

	
	function display(){
		
		if(isset($this->vars)){
		extract($this->vars);
		}		

		$page = basename($_SERVER['SCRIPT_FILENAME']);
		$page = str_replace('.php','', $page);

		
		$template = $page . '-tpl.php';
		return include('templates/'.$template);
			
	}

}

?>
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

As for a template engine, use XSLT. It forces you to marshal your data into a content neutral format (XML/DOM) and then lets you convert it to HTML or whatever else you want. Template-based solutions still don't do a good enough job of enforcing business/presentation logic separation without strong developer discipline.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

I've had great successes with Template Lite. Love it.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply