converting html website to simple PHP templated site
I've got a simple website of a friend. It is setup with 15 or so html pages which follow the same template. I've been asked to take a look at it and change a thing or two. The work is easy if it were not for it being duplicated so heavily.
What is a good templating engine for PHP that I could use to make it so that I only need to make layout changes in one file instead of ~15?
I suppose all I really need to do is define a single function, where the function contains the template code, and the caller specifies the inner html to use... But I suppose there may be a better tool for this in the PHP world that I am unaw开发者_开发问答are of.
You may lookup Smarty. This is one option of a very stable templating engine which is pretty long in the wild. Another thing would be to take something more recent like Mustache.
For a simple web site of a dozen of pages just create a couple of PHP files with common parts. E.g. header.php and footer.php and then include these files in all your static pages. They'll look like
<? include "header.php"; ?>
Actual content goes here ....
<? include "footer.php"; ?>
It's a common approach. Actually, footer.php and header.php may be complex and include other .php files (e.g. top_menu.php, news.php, secondary_menu.php, and so on)
In your case a kind of CMS or a framework would be an overhead.
精彩评论