What do you use for templating?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

alvinphp
Forum Contributor
Posts: 380
Joined: Wed Sep 21, 2005 11:47 am

What do you use for templating?

Post by alvinphp »

For those that use templating did you build your own template class or use something like smarty?
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

I use Smarty, although for a brief period I used Template-Lite, and if the security protections from it get ported to Template-Lite, I'll switch back to it.

I've looked at other solutions, but Smarty and TL are full featured enough that I haven't yet "hacked around" a limitation they have, while they are also small enough, and well-maintained enough that it keeps me happy.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

I tend to switch between PHP, str_replace and XSLT templates -- even on the same page -- because I use hierarchical templates/response. So I have a set of little classes that implement minimal functionality. The whole thing is under 5k.
(#10850)
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

Smarty was too slow and bloated so I helped write an alternative that was compatible with Smarty Syntax. It has become a very popular replacement/alternative to Smarty. :) The link is in my signature. :D
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I use PHP ;)
User avatar
MrPotatoes
Forum Regular
Posts: 617
Joined: Wed May 24, 2006 6:42 am

Post by MrPotatoes »

my own custom templating sytem. i've gotta add some more better functionality to it but it's wicked fast and tiny.

too bad i'm having problems with something currently. <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span> forum code. *ugh*

Jcart | watch your language please
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

I use PHP deriving mine from bTemplate...

Simple and fast...

Occasionally I'll use Smarty (now Template Lite)...
User avatar
MrPotatoes
Forum Regular
Posts: 617
Joined: Wed May 24, 2006 6:42 am

Post by MrPotatoes »

Hockey wrote:I use PHP deriving mine from bTemplate...

Simple and fast...

Occasionally I'll use Smarty (now Template Lite)...
i took a few cues from that one. i looked it over and that'st he one that i wanted to play with over the others
Gambler
Forum Contributor
Posts: 246
Joined: Thu Dec 08, 2005 7:10 pm

Post by Gambler »

<?= ?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Gambler wrote:<?= ?>
ack. That's all I need to say without going into a rant.

Anyways... I use whatever makes sense at the time and as the needs of the people involved require. Sounds wishy-washy, but it's the truth. I will use whatever they want/need me to. They are paying for it, so it's their choice.
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

Gambler wrote:<?= ?>
That will not work on server that has short tags disabled and most new versions of PHP have short tags disabled by default.

You would have to use something like...

Code: Select all

<?php echo $variable; ?>
...instead of what you posted above.
alvinphp
Forum Contributor
Posts: 380
Joined: Wed Sep 21, 2005 11:47 am

Post by alvinphp »

AKA Panama Jack wrote:
Gambler wrote:<?= ?>
That will not work on server that has short tags disabled and most new versions of PHP have short tags disabled by default.
I have yet to see a public hosting company disable <?= ?>. And that includes newer versions of PHP. If you did disable the short tag a lot of legacy PHP and scripts would crash.

After some research I decided to stick with native templating (using <?=?>). Thanks for all the input!
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I have no issues with seeing the use of "echo" and "print" in templates. It's logical and more obvious than a lot of template systems. Personal preference, that's all.

IMO, PHP provides all the constructs and more than you need to manage templating. Doing it this way reduces memory, increases speed and lets PHP do what it does well. Adding another layer to do the templating may provide some features that you'd need to otherwise code but I don't feel that those benefits far enough outweigh the advantages of just using PHP.

OK so this is not a real template system but it's along the lines some of the follow but why is:

Code: Select all

<table>
    {foreach %something = x}
    <tr>
        <td>%x</td>
    </tr>
    {end-foreach}
</table>
Any better than:

Code: Select all

<table>
    <?php foreach ($this->something as $x) { ?>
    <tr>
        <td><?php echo $x ?></td>
    </tr>
    <?php } ?>
</table>
EDIT | Don't get me wrong, I used to use template systems and actually wrote a few that introduced some new concepts so I'm not bashing them, I just have come to see that PHP already does everything that these systems are doing... but faster.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The only time I push hard away from using PHP is when maintainence comes into play. More often than not, the person doing the maintainence will not have the knowledge necessary to correctly write the php, so I'll suggest more template engine systems to the client.

Now, when I do my php level templating, there's no business logic involved. It's purely display logic only. Keeping them separated is the key to keeping it all more easy to maintain, I feel.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

TemplateLite. I think it is better and faster than Smarty. I use to use the phpBB template class, but it was slowing my apps down quite a bit, so I switched. I have also toyed around Savant, but that is just a PHP derivative that ends up using PHP syntax (it supports caching and such, but still not as user friendly as TL).

I have, on ocassion in the past, used PHP as my templating engine as well. It is well built for it. Just a little difficult to maintain the presentation code for designers that do not understand the PHP logic involved in displaying presentation.

PS Short tags should never be relied upon to be enabled. Even if you have never encountered a host that disables them, it doesn't mean that PHP will continue to support them.
Locked