0

Let's say I have a script, content.php, which acts as a template. It will get the name of the page from the request. Each page is expected to have a title and meta tag values.

Is there a way that I can set these values from within each page?

The following is a sample:

content.php

<?php
include "header.php";
include "content/{$_GET['page']}.php";
include "footer.php";
?>

header.php

<html>
    <head>
        <title><?php echo $title ?></title>
        <meta name="title" content="<?php echo $meta['title'] ?>">
        <meta name="description" content="<?php echo $meta['description'] ?>">
        <!-- and other elements that goes here -->
    </head>
    <body>

footer.php

    </body>
</html>

I would like to be able to do something like this WITHOUT adding any includes inside:

page1.php

<?php
$title = 'Some Title';
$meta = ['title' => 'Some Title', 'description' => 'Some Description'];
?>

My Content

And unfortunately, I cannot use any template engines.

  • `include "content/{$_GET['page']}.php";` uhhhhm you realize I could do funky stuff with this right? – PeeHaa Oct 25 '14 at 16:24
  • lol yes, I am just keeping it simple. – Lynn Adrianna Oct 25 '14 at 16:31
  • @LynnAdrianna: Something as simple as`content.php?page=../content`? – hakre Oct 25 '14 at 17:17
  • @hakre Um.. why are you focused on the irrelevant part of my problem? What I wrote is just a shorten illustration. – Lynn Adrianna Oct 25 '14 at 17:32
  • @LynnAdrianna: If that part is irrelevant, why is it part of your question? For the other part, you *could* refer to existing material like: [Is include()/require() with “side effects” a bad practice?](http://stackoverflow.com/q/7697389/367456) and similar others. – hakre Oct 25 '14 at 19:12

1 Answers1

0

I use code like this, this way I can change parts of the header file in a given file by placing the information in the file before hand. Of course in the example below there is a table with a right side, middle and left side in it. You can use the same concept for what you are trying to do.

if(!$righthead){
    $righthead=     "content";
}

if(!$midhead)
{
    $midhead="<img src=\"/images/cover.jpg\" width=\"391px\"/>";
}

if(!$lefthead){
    $lefthead="content";
}

if(!$title){
    $title = "content";
}

if(!$robot){
    $robot = "INDEX,FOLLOW";
}
?>
kayleighsdaddy
  • 670
  • 5
  • 15