
01-17-2009, 04:30 PM
|
|
|
Hello,
I'm working on a website for a guy and I was trying to think of a way to make it easier for him to add content to it. My thought was to make two html documents. One with all the layout information and colors and another that holds the text that gets displayed in the main body. That way he only has to edit the one with the text and never has to mess with the coding.
After looking around I haven't found any way to do this easily, although I know you can import external CSS documents and thought it would be a similar process.
If anyone knows how you can do this I would greatly appreciate the knowledge.
|

01-17-2009, 09:25 PM
|
|
Community Leader
|
|
Join Date: Oct 2002
Location: cognito
Posts: 17,321
|
|
Simplest way would be to include the external doc by using a PHP page instead of HTML as the one to display it in. Make your page as usual, but where the content is to be included:
<?php include('/path/to/included/file.ext'); ?>
There are probably a dozen other ways, but that's the simplest, I feel.
|

01-17-2009, 09:31 PM
|
|
|
Thanks,
I tried it but the text didn't show up when I loaded the main page. Could you elaborate more for me? Does the external doc have to be php or the one calling it?
|

01-17-2009, 09:51 PM
|
|
Community Leader
|
|
Join Date: Oct 2002
Location: cognito
Posts: 17,321
|
|
In order for the page to be included, the calling page needs to be parsed by the PHP engine. By default, naming it with ".php" at the end is how it's done.
You could also tell the server to parse HTML pages in the same way, but it's not recommended, mainly because if something goes wrong...it will happily expose all your PHP code, and it adds extra overhead to rendering all HTML pages.
|

01-18-2009, 11:58 AM
|
|
Web Hosting Evangelist
|
|
Join Date: Jun 2008
Location: Glasgow, United Kingdom
Posts: 480
|
|
There is also SSI.
You will need to change the extension to .shtml instead of .html.
<!--#include virtual="header.html"-->
header.html would be where your code is.
|

01-18-2009, 09:48 PM
|
|
|
Uhm, I think I'm a little confused. I have a regular html document and I want it's contents to show up on another page. I've tried these and all I get is a blank page.
|

01-18-2009, 09:58 PM
|
|
Community Leader
|
|
Join Date: Oct 2002
Location: cognito
Posts: 17,321
|
|
Do you have PHP installed on the server? The method I gave requires it. Make one page that will serve as the recipient of the external page's content. In it place any content and layout you like, and where you want the external HTML page to appear add the include.
<?php include('/path/to/included/page.html'); ?>
This path must be correct.
Name the page with the above code in it anything you like, as long as it ends with ".php".
Still having trouble? Post your code.
|

01-19-2009, 05:09 AM
|
|
|
If you create the following four files and place them in the same directory as each other, when index.php is visited, each of the following files will be included. There are several different types of includes. include(), include_once(), require() and require_once(). They're all used in the same way, simply specifying the filename as the parameter so include('header.html'), include_once('header.html'), require('header.html') and require_once('header.html'). The difference between include and require is that if you're using require, and the file isn't found, the page won't continue loading, however with an include, the page will just load without that include. The addition of _once simply checks if that file has already been included, and if so, doesn't include it again.
index.php
<?php include('header.html'); ?>
<?php include('content.html'); ?>
<?php include('footer.html'); ?>
header.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Page</title>
</head>
<body>
<div id="content">
content.html
<p>Any content placed in this file is positioned in between the <div id="content"> and the </div> tag in the header and footer, respectively.</p>
footer.html
</div>
</body>
</html>
|

01-19-2009, 03:22 PM
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
| Postbit Selector |
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
| Login: |
|
|
| Advertisement: |
|
|
| Web Hosting News: |
|
|
|