Jump to content

Recommended Posts

I'm building a very big website, and for the PHP+XHTML documents, I use a template. For example (highly simplified):

 

home.php:

include template.php
function mainContent() {
echo('content here');
}

template.php:

echo('<html><head><style type="text/css" src="style.css" /></head><body>');
mainContent();
echo('</body></html>');

 

On the other hand, we use this approach where I work:

 

 

home.php:

include template.php
header();
echo('content here');
footer();

template.php:

function header() {
echo('<html><head><style type="text/css" src="style.css" /></head><body>');
mainContent();
}

function footer() {
echo('</body></html>');
}

 

The first approach is a lot nice imo, but in some cases I have to selectively include template.php where some executions of the script result in new header information being sent. This results in code repetition (having to add "include template.php" in multiple places) and hard to read code.

 

Are there any other ways of doing it beside these?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/103074-best-way-to-implement-php-template/
Share on other sites

An example:

 

http://www.codewalkers.com/c/a/Display-Tutorials/Writing-a-Template-System-in-PHP/

 

If you are really looking at a large scale site, I would use a framework of some sort...makes life somewhat easier.  I like zend framework personnally.

 

http://framework.zend.com

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.