views:

92

answers:

3

I wonder what options there are for templating in PHP? If the templating code can be very similar to PHP, it'd be best.

+2  A: 

Well since PHP is a templating engine there's always... PHP.

Some feel the need to add more. Smarty is very popular. Personally I've never seen the point but to each his own.

cletus
+4  A: 

I can recommend Smarty

The template is a plain HTML with some extra markup for PHP calls. The template compiles itself to a PHP and runs on the server.

pgb
Worth mentioning that smarty has some pretty powerful server-side caching.
karim79
+4  A: 

there is an "alternative" syntax to php that makes it more attractive amidst html tags, I can highly recommend it.

Short tags, though mostly discouraged and/or ridiculed also have a nice advantage:

<?php echo $variable; ?>

can become:

<?= $variable; ?>

And you can do stuff like:

<ul>
    <? foreach ( $myListItems as $id => $itemText ) : ?>
    <li id="<?= $id; ?>">
        <?= $itemText; ?>
    </li>
    <? endforeach; ?>
</ul>

Which is the lowest level templating you are going to achieve with php, but is still very readable and it does not require you to mix in controller or model logic with your view.

Kris