0

Hi all, I am doing a website which will have a large amount of files uploaded to it which only the admin will upload files to it, users can't.

I split the template in parts, the banner in its own .php file, the navigation bar in its own and so on. ( including the body template on its own too.)

In the index (main page), with php I am including the other pages, so when I wish to edit the banner, I dont have to go on every page editing the same thing, but I will edit the banner from the banner.php only and the changes will be effected on all the pages.

Now for the body( where the content will be ) I cant use the same template ( with only one "main_panel.php" page) as the content will be different.

I have to duplicate the body template for each content and when I wish to edit the body template I have to go on every page to make a change to the body template.

My question is, how can I have only one main_panel.php(the body template) page as a template and the content will be on other different pages.

If you didnt understand well (which I guess you did as my english is not so good) dont hesitate to ask questions.

If you want to check other things, I have the site uploaded at www.elemen7s.com

Below is the index page and the body template.

index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Elemen7s | Home</title>
<link href="template/CSS.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
    margin-left: 0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
}
-->
</style>
</head>

<body>
<div class="Whole">

<?php include "template/login.php"; ?>

<?php include "template/banner.php"; ?>

<?php include "template/navigation_bar.php"; ?>

<div class="Body">

<?php include "template/left_panel.php"; ?>

<?php include "template/main_panel.php"; ?>

<?php include "template/right_panel.php"; ?>

</div>

</div>

<?php include "template/copyright.php"; ?>

</body>
</html>

main_panel.php ( the body template)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="template/CSS.css" rel="stylesheet" type="text/css" />
</head>

<body>
    <div class="Middle">
        <div id="Middle_Title"></div>
        <div id="Middle_Body" style="text-indent:5px">
            <!-- Here the content of the website will be -->

        </div>
        <div id="Middle_Bottom"></div>
      </div>
</body>
</html>
3
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by Elemen7s
0

If I understand it correctly, maybe you could do it this way:

<?php
function curPageName() {
 return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
}

$curPage = curPageName();
switch $curPage {
   case ($curPage = "index.php") : include(index-body); break;
   case ($curPage = "next.php")  : include(next-page-body); break;
}
?>

This should go on line 12 on so on in main_panel.php

What it does is this, the function will give you the page name part of the url and the switch will insert the body part for this page.

Edited by colweb: corrected an error

0

Could you tell me which lines should I edit to make it work on my website.

Thanks for replying mate

Edited by Elemen7s: Spelling

1

Reasonable answer already, although I didn't really analyse it.

You're using self-made templates - well done! This is the intermediate step to going model-control-view (Smarty, Rain TPL etc), and often the easiest way of doing things.

Many of my own sites pretty much follow your idea. I simply have a contents folder with the content for a specific page having the same name.

Eg.

index.php
about.php
contact.php
contents/index.php
contents/about.php
contents/contact.php
includes/config.php (language settings etc)
includes/functions.php (get js scripts etc)
includes/top.php (DTD, Head, Banner, Nav - although these can be split further)
includes/bottom.php (footer and end tags [/body, /html])
includes/side.php (sidebar)
templates/main.php

Content of index.php:

<?php
//set variables for specific js scripts etc.
//e.g. $extrascript['jquery'] = 1; - this will tell a script in functions.php to write a <script> tag for jquery 
$page['title'] = "This is my homepage";
$page['desc'] = "This is a description";
$page['keywords'] = "kword1, kword2, kword3...";
//any other head/meta stuff
include("templates/main.php");
?>

That's it - every main page (about.php, contact.php) looks pretty much the same.

Content of template/main.php

<?php
$content_name = basename($_SERVER['PHP_SELF']);
include("includes/config.php");
include("includes/functions.php");
include("includes/top.php"); //this calls sidebar etc as well
include("contents/$content_name");
include("includes/bottom.php");
?>

Perhaps I should mention that the top.php file does a heck of a lot behind the scenes.

A snippet:

<head>
<title><?php echo $page['title'];?></title>
...
</head>

I won't pretend that this is the best way to do things, but it works and it's flexible, without the complexity (I can hear experts loading their shotguns now!) of something like Smarty. If you want to use a different template - easy.

Edited by diafol: n/a

Votes + Comments
Thanks for helping mate
0

Thanks mate thats what i wanted :)

Edited by Elemen7s: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.