Reputation: 8245
I've been having some trouble with the structure of my php website lately...
It's a bit of a mess. I have includes for the header, the navigation and the footer on all the content pages, but I don't know where to put the container div that the content goes into.
Since most of my development skill and experience lies in .net, I'm trying to find a way to duplicate the sort of functionality that master pages offers, but I'm at a loss on where to start...
Can anyone point me in the right direction here?
EDIT 1
Okay so I've found this: Website Structure
I only have one question...
The header for my HTML looks something like this:
<html lang="en-us" data-page-id="<whichever page you're on>">
<head>
<title>Whichever page you're on</title>
<link href="/css/core.css" type="text/css" />
<!-- dynamically write in meta tags (and possibly .js file references) -->
</head>
My question is this: how can I dynamically change the title on each content page and dynamically set the script references depending on what content I'm looking at?
Upvotes: 0
Views: 2128
Reputation: 11943
Assume you have a file called header.php
, which contains the above mentioned HTML. Simply replace all the parts you want to generate dynamically with PHP strings and echo them out (making sure you wrap them in PHP tags) like so...
<head>
<title><?php echo $title ?></title>
<link href="/css/core.css" type="text/css" />
<!-- dynamically write in meta tags (and possibly .js file references) -->
<?php
include 'metatags.php';
include 'javascript.php';
?>
</head>
Notice the above code also adds two include statements to include two more files for your dynamically generated meta tags and javascript. The same concept applies.
The PHP script including this will define the dynamic content as strings or through other included PHP scripts that generate those strings, like so...
<?php
$title = "Some dynamically generated title...";
include 'header.php';
?>
The above file would be an example of your index/master page as you'd like to call it. PHP will do the rest. Define the logic for defining your $title
string as necessary there.
Upvotes: 1