Jump to content

Template Engine Recommendations/Comments/Advice


samona

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

... 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? 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.