Jump to content

Archived

This topic is now archived and is closed to further replies.

devbanana

Perfect templating system?

Recommended Posts

What, in your opinion, would the perfect templating system be like? I'm not looking for systems that have been already made, but features that you would want to see in a good templating system. Please be realistic. :)

I know some people just like to have PHP intermingled with HTML, such as:

[code]Hello <?php echo $user?>.[/code]

But I don't really like this. It would be too tempting to do some processing in the presentation layer that does not belong in the presentation layer, plus I think it is too messy, as far as syntax is concerned.

I'm thinking of, perhaps, a declarative syntax, that would mostly look like regular HTML, but would be parsed by the template system and replaced.

Share this post


Link to post
Share on other sites
Great to see this is generating such an enthusiastic response. ::)

Well, in spite the fear of talking to myself...

I have been checking out XSLT, and it seems like it'd be a very nice tool to use for templating. A bit complicated, but at least it is a standard, and it can output various formats, so it doesn't necessarily need to be bound to outputting HTML/XHTML.

Share this post


Link to post
Share on other sites
[quote author=steelmanronald06 link=topic=105698.msg423288#msg423288 date=1156768849]
SMARTY
[/quote]

Hi,

Thanks for the reply. However, as I mentioned in my first post, I'm not looking for existing templating systems, but what features you would look for in a templating system.

I don't like Smarty, because the logic is too imparative. If you're going to use Smarty, you may as well just use PHP for presentation logic, because they're both just as imparative.

Share this post


Link to post
Share on other sites
Honestly, I can't really say. I create my own template systems for each project I do.  That way I have a system that is unique and custom to each project.

Share this post


Link to post
Share on other sites
off the back of this article:

http://www.massassi.com/php/articles/template_engines/

i created my own. the problem with templating engines is, whilst they offer plenty of other features, they're just ultimately a new set of syntax. people take the "seperation" a bit too far, when the actual idea is just to seperate your "business" logic from your "presentation" logic. no matter how hard you try, its not really possible to remove ALL of your code from the HTML - no matter how you dress it up, re-syntax it, etc.

ok, so some people don't like using php short tags. but if they do, is typing <?=$name; ?> really that much harder than {name} ? and many of these 'Engine' templates also use similar methods for looping, whereas the 'foreach' in PHP is simple enough in itself, without the need to replace it with a new set of syntax.

in terms of what i look for - just something lightweight and simple that keeps the bus/pres logic as seperate as possible. i literally have 3 main functions in my template class other than the constructor:
1. function to set a variable
2. function to load a (sub)template to a variable
3. function to output

seriously, the link i posted above is definitely an excellent read which, in itself, covers most of your queries.

hope that helps a bit
Cheers
Mark

Share this post


Link to post
Share on other sites

×

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.