nonopolarity
nonopolarity

Reputation: 151036

what templating engine options are there for PHP?

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

Upvotes: 0

Views: 297

Answers (3)

Kris
Kris

Reputation: 41837

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.

Upvotes: 4

pgb
pgb

Reputation: 25001

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.

Upvotes: 4

cletus
cletus

Reputation: 625097

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.

Upvotes: 2

Related Questions