View Single Post
  #4   Spotlight this post!  
Unread 26-11-2004, 00:04
Joel J's Avatar
Joel J Joel J is offline
do you..
no team
 
Join Date: May 2001
Rookie Year: 2000
Location: San Jose, CA
Posts: 1,445
Joel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond repute
Re: PHP template engine

I remember looking into this a while back. I believe I came to the conclusion that Smarty had the best concept of what a template engine should be. That is, not simply an engine for replacing placeholders with relevant content, but an engine that facilitates the separation of application logic (getting the last 10 posters in this forum from the database) from presentation logic (increasing the size of a posters name if they are a moderator). However, Smarty is a feature rich template engine. So much so that it is becoming a programming language all of its own. This reality causes many programmers to cry down the use of Smarty, because they think it has lost sight of what a template engine should be. I have to admit, I took this position for a while, but as I thought about it more I realized that if a designer chose to limit himself (herself?) to the core elements of Smarty, then the overdone nature of Smarty becomes irrelevant. Added to that, the designer still benefits from some of the nicer features of Smarty (caching, etc..) that are not present in other template engines.

So I guess I'd recommend a controlled use of Smarty: use the elements you need, and ignore those that are unnecessary, or that will cause a deviation from the true purpose of a template engine.

PS: I ended up just writing my own template engine. Smarty was an excellent engine, but it lacked a few features that I really wanted to have (storing and retrieving templates from a database, etc..). Smarty was designed in a way that allows its users to add custom functions, so I could've integrated the missing features that way, but you know.. lazy.

edit:

Something along the lines of:
Code:
<html>
<head>
  <title><var name="title"></title>
</head>
<body>
  <h1><var name="forumname"></h1>	
  Last 10 posts:
  <ul>
    <repeater name="posts">
      <li><var name="posts.title"> (in <var name="posts.parentthread">) <br /> <var name="posts.author"></li>
    </repeater>
  </ul>
</body>
</html>
is easier for a website designer to look at and grasp than:
PHP Code:
<html>
<head>
  <title><?php echo $title ?></title>
</head>
<body>
  <h1><?php echo $forumname ?></h1>    
  Last 10 posts:
  <ul>
    <?php foreach ($posts as $post): ?>
      <li><?php echo $post['title'?> (in <?php echo $post['parentthread'?>) <br /> <?php echo $post['author'?></li>
    <?php endforeach; ?>
  </ul>
</body>
</html>
Why? Because web designers often know nothing beyond HTML/CSS. In addition, HTML is more like a structure providing language than an actual "programming" language, so the ability to understand, edit, and create HTML pages does not imply the ability to pick up on programming languages (even PHP, as simple as it is). Therefore, the template engine, should it want to be friendly to its user, should make its format resemble HTML as much as possible. My goodness, do you remember when you first had to grasp the concept of accessing elements of an array using square braces? Better yet, having to explain, in an understandable way, what square braces after a variable name does? Presentation does make a difference.

Smarty's tags resemble PHP rather than HTML, and it does make it somewhat harder to learn (or explain to someone). But for this second response, I'm not talking about Smarty, but template engines in general.

PPS: I know PHP, but I would personally rather deal with the HTML-like template tags when designing pages. It may just have to do with my mindset.
__________________
Joel Johnson

Division By Zero (229) Alumni, 2003-2007
RAGE (173) Alumni, 1999-2003

Last edited by Joel J : 26-11-2004 at 01:41.