Saturday 9 July 2011

PHP Master page concept

There is no such thing in php; however, there are 2 functions you can use to simulate that.

include() and require().

Include will continue processing the page even if the file isn't there or readable; while require will fail if the file isn't there or readable.

So an example of this would be:

template.php

PHP Code:
<!DOCTYPE html>
<html>
    <head>
        <title><?php echo $title?></title>
    </head>
    <body>
        <?php echo $content?>     </body>
</html>
contentX.php
PHP Code:
<?php

$title 
'Something';
$content = <<HTML
    
<h1>Title</h1>
    <
h2>Sub Title</h2>
    <
p>Some static text</pHTML;

require(
'template.php');