Forum Moderators: coopster

Message Too Old, No Replies

how to create website template

         

Skier88

5:59 am on Sep 11, 2009 (gmt 0)

10+ Year Member



My goal is this: individual webpages, say myinfo.html, contain just the content, eg "this is my content", and that's it. However, when it's loaded, the header and surrounding tags are automatically inserted - this includes links, title, meta, logo, menu, search box, and box that goes around content. The text can be accompanied by a line or two of code, but the goal is to have only one file indicate the styling of my website. And using php files instead of html is fine... I just want only one copy of each file - meaning, no empty myinfo.html and a separate myinfo.txt. Also, the original content of the html file must be able to use tags, like hr, img, and h1, and be styled by the inserted stylesheet. I hope I'm asking in the right forum... thanks for reading.

Tommybs

6:41 am on Sep 11, 2009 (gmt 0)

10+ Year Member



Hi there,

The functions you need to look into are include/require in the php manual. The basically allow you to include various files within another. So for instance, you could have a file named header.php that contains something like

<?php
defined("SomeText") or die("you cannot call this file directly");
?>
<html>
<head>
<title><?php echo $page_title = isset($page_title) ? $page_title : "mysite.com"; ?></title>
<link rel="stylesheet" src="" />
</head>
<body>
<img src="logo.jpg" alt="Logo" />
<div id="navbar">
<a href="link1.php">Link 1</a>
<a href="link2.php">Link 2</a>
<a href="link3.php">Link 3</a>
</div>

Then do something similar for a file named footer.php

In you myinfo.php you would then do.


<?php
$page_title = "My Info";
define("SomeText", TRUE);
include_once("header.php");
?>
<h1>My Info</h1>
<p>This is whatever information I want to put in here</p>
<?php include_once("footer.php"); ?>

Skier88

8:16 am on Sep 11, 2009 (gmt 0)

10+ Year Member



thank you, that actually answers my question. I had been playing around with include_once, but for some reason the simple solution of two template files never occurred to me.

While this answers my question, just out of curiosity: is it possible to automatically modify any html page fetched from your website? So you wouldn't even need include_once on the content page. I think imageshack does this with hosted images...

Tommybs

8:26 am on Sep 11, 2009 (gmt 0)

10+ Year Member



No problem, glad I could help.

I think you may be talking more about fopen and fread although I'm not quite sure I get what you mean in the 2nd part, sorry. Take a look at those functions and see if it's what you're after. If not maybe someone else might be able to help you. Either way I think you need to include something whether it's via include or reading a file and adding it's contents.

The other option is something like how phpbb uses template files and placeholders I guess...

Skier88

8:34 am on Sep 11, 2009 (gmt 0)

10+ Year Member



include_once is just what I was looking for. I was just wondering about something I saw, but I think it has to do with .htaccess and/or asp, not php.