samona Posted December 19, 2009 Share Posted December 19, 2009 Hi, I was wondering what PhpFreaks users would recommend as far as template engines. I would like to build a small website and I was thinking of using the PEAR template engine ITX. However, I'm not sure if this would be the best way. I heard about Drupal and about how flexible it is, and was wondering if anyone thinks that that would be the best route. Thanks in advance for your advice and comments. Quote Link to comment https://forums.phpfreaks.com/topic/185664-template-engine-recommendationscommentsadvice/ Share on other sites More sharing options...
trq Posted December 19, 2009 Share Posted December 19, 2009 Firstly, Drupal is a CMS and framework, not exactly a template engine. As for template engines.... why do you want to use one? All they really do is add another layer to your application which usually effects performance. A well designed application separates business logic from presentation logic and could use just a small subset of php itself within html to create much more efficient (and IMO easier to maintain) templates. Quote Link to comment https://forums.phpfreaks.com/topic/185664-template-engine-recommendationscommentsadvice/#findComment-980375 Share on other sites More sharing options...
samona Posted December 19, 2009 Author Share Posted December 19, 2009 Quote ... A well designed application separates business logic from presentation logic and could use just a small subset of php itself within html to create much more efficient (and IMO easier to maintain) templates. How do you separate business logic from presentation logic without a Template Engine? Quote Link to comment https://forums.phpfreaks.com/topic/185664-template-engine-recommendationscommentsadvice/#findComment-980377 Share on other sites More sharing options...
trq Posted December 19, 2009 Share Posted December 19, 2009 You might want to look at the MVC design pattern, its one easy way to separate your application from presentation. But a simple example (without even going down the mvc road) could be something as simple as.... index.php <?php $sql = "SELECT title, article FROM articles": if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $articles = array(); while ($row = mysql_fetch_object($result)) { $articles[] = $row; } } } include 'template.php'; ?> template.php <html> <head> <title>articles</title> </head> <body> <?php foreach($articles as $article): ?> <div class="article"> <div class="title"><?php echo $article->title; ?></div> <div class="content"><?php echo $article->content; ?></div> </div> <?php endforeach; ?> </body> </html> Of course that a really simple example but you can easily see how you could build on and improve the idea. Quote Link to comment https://forums.phpfreaks.com/topic/185664-template-engine-recommendationscommentsadvice/#findComment-980380 Share on other sites More sharing options...
teamatomic Posted December 19, 2009 Share Posted December 19, 2009 I have made something like what you might want. Its at myphptemplate.co.cc. It has no editor, it just builds a menu from the files in the content folder and displays them in the content area. You can use headers for each page if desired. All the display and menuing is automatic, all you need to do is make the fragments and upload them to the right folders. The config file is fairly well commented. You can get it from myphptemplate.co.cc at the download page. HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/185664-template-engine-recommendationscommentsadvice/#findComment-980382 Share on other sites More sharing options...
samona Posted December 19, 2009 Author Share Posted December 19, 2009 Quote You might want to look at the MVC design pattern, its one easy way to separate your application from presentation. But a simple example (without even going down the mvc road) could be something as simple as.... Yes! I see what you're saying. I'll also check out the MVC design pattern because it's the first of heard of it. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/185664-template-engine-recommendationscommentsadvice/#findComment-980383 Share on other sites More sharing options...
roopurt18 Posted December 19, 2009 Share Posted December 19, 2009 As thorpe pointed out, a template engine is not the same as a CMS. You should make sure you really understand what they each are before you possibly confuse yourself. Anyways, PHP is a template engine. There's absolutely no reason to use any template language / engine such as smarty. Any person that can learn a template language can just as easily learn the four or five language elements of PHP required to use it instead. And since they'll be collaborating with a PHP developer anyways, the PHP developer will usually be on hand to answer simple questions about PHP. Quote Link to comment https://forums.phpfreaks.com/topic/185664-template-engine-recommendationscommentsadvice/#findComment-980385 Share on other sites More sharing options...
samona Posted December 19, 2009 Author Share Posted December 19, 2009 Thank you all for your responses. Quote Link to comment https://forums.phpfreaks.com/topic/185664-template-engine-recommendationscommentsadvice/#findComment-980388 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.