|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#2
|
||||
|
||||
|
Re: PHP template engine
I tried using Smarty, and I couldn't get it to work. Granted, I already had an entire page created, and it was a hack and slash kind of conversion, and I didn't put nearly as much effort into it as I should've. If you take the time to learn it though, Smarty seems to be pretty simple to use.
Last edited by Ian W. : 25-11-2004 at 17:57. Reason: Firefox + TagAlert leaves cruft in quotes with hyperlinks |
|
#3
|
||||
|
||||
|
Re: PHP template engine
I've heard good things about patTemplate (http://www.php-tools.de/site.php?fil...e/overview.xml) and SmartTemplate (http://www.smartphp.net/content/smar...out/about.html)... my experience with them is limited, but I liked how "lightweight" they felt.
There is always the "easy" option of just plain PHP. TBH, 99% of the time, auto_prepend, auto_append, and a normal PHP page will do the job just as well, all without having to learn a new language. When you pick up a template package, like it or not, you are usually learning a new programming language, and I have always felt that this is simply overkill. PHP is a fine templating language, it comes with blocks, if/else structures, and everything else you could possibly need. And don't tell me that <!-- IF var -->....<!-- ENDIF --> is somehow simpler than <?php if ($var) { ?> <?php } ?>, they're essentially the same thing in the end. Skip the process of converting templates into PHP programatically and just write PHP from the start. :-/ |
|
#4
|
||||
|
||||
|
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>
PHP Code:
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. Last edited by Joel J : 26-11-2004 at 01:41. |
|
#5
|
|||||
|
|||||
|
Re: PHP template engine
If you're looking for a very basic templating system, they're pretty simple to write. The one I wrote is about 30 lines of code. You basically load all your data you want to put into the template into an array, then load your template, and search and replace. I've never used one of the already-made ones but I hear a lot of talk about Smarty. Like Joel said, it's great if you keep it simple.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Speaking of PHP 5... | Ryan M. | IT / Communications | 3 | 01-08-2004 16:46 |
| openFIRST PHP 5 Compatibility | Timothy D. Ginn | FIRST-related Organizations | 0 | 30-07-2004 13:45 |
| PHP and Wiki Error | Venkatesh | Website Design/Showcase | 2 | 24-07-2004 15:51 |
| php vs. perl | Jack | Website Design/Showcase | 20 | 29-12-2002 17:01 |
| What's better, PERL/cgi or PHP/my_sql? | mikefrei | Programming | 10 | 27-05-2002 22:50 |