简体   繁体   中英

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 unaware 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. Eg 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 (eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM