Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebDesign: Header file, but with custom Page titles?

I've been using headers to create templates for websites. It's easy, and very convenient for debugging.

I now face the problem of using head BUT with custom page titles. If this is my header.php >

<html>
    <head>
        <title> My Site : ??? </html>
    </head>
<body>


</body>
</html>

I need ??? to be replaced for every page.

Is this possible? If so, how? Thank you. : )

like image 783
n a Avatar asked Apr 28 '10 18:04

n a


2 Answers

Not knowing more about your file inclusion scheme, the simplest way would be:

page2.php

<?php
$pageTitle = 'Page 2';
include 'header.php';
?>

<div>My content</div>

<?php include 'footer.php'; ?>

header.php

<html>
    <head>
        <title> My Site : <?php echo $pageTitle ?> </title>
    </head>
<body>

footer.php

</body>
</html>
like image 172
webbiedave Avatar answered Sep 30 '22 16:09

webbiedave


webbiedave's answer is perfectly fine, but in the long run, you should really learn to use either a decent template language (Smarty, Twig), or a PHP framework that has it's own templating. Kohana and Codeigniter are both pretty easy to get into.

like image 38
Bopp Avatar answered Sep 30 '22 17:09

Bopp