Re: including HTML
| From: | Justin French | Date: | Wed, 07 Aug 2002 23:34:45 +0000 |
| Subject: | Re: including HTML | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-111593@lists.php.net to get a copy of this message | ||
I really don't agree with this method of doing things.
Because what you end up with are lots of HTML pages, all of which are
different. When they DO want to change from HAPPY CO to HAPPY AND SONS,
they'll have to open 10's or 100's or 1000's of HTML pages and make that
change.
SCREW THAT!!!
You need a templating system. It doesn't have to be too elaborate, but
doing something as simple as:
site.com/page.php?pageid=4
<?
// HEADER
include('inc/header.inc')
// SPECIFIC CONTENT
$include = "content/page_{$_GET['pageid']}.txt";
if(file_exists($include) {
include($include)
} else {
echo "sorry, page could not be found";
}
// FOOTER
include('inc/header.inc')
?>
This gives you just TWO FILES to maintain for the header and the footer of
every page on your site. The header would include Javascript, the
<!DOCTYPE, <HEAD>, CSS, <BODY>, maybe tables, and everything else you need
to get the the point just before the content. The footer would be
everything after the main content, all the way down to </HTML>.
Then the client (or you) can change the heading text to HAPPY & SONS on ONE
FILE, and it is reflected on the whole site.
Then you only have a series of text based content files named:
page_1.txt
page_2.txt
Essentially, these could be raw text, or pseudo HTML with some simple
<B><U><A><I> formatting, and perhaps tables where needed.
Let the client do this if they want, or if it's too complex, they pay you.
You pass the pageid # to page.php in the url, and it looks for the file
page_nn.txt... if it's there, it includes it, if not, it echo's an error
(which could be another include file.
You're separating the common stuff (headers, footers, etc) from the unique
stuff (content).
I honestly can't imagine doing a content-oriented site like this any other
way any more!!
The other way is to have a unique file for each page:
about.php
services.php
etc
Each one of those looks like:
<? include('inc/header.inc'); ?>
<B>This is my HTML for the About page</B><BR />
Hello
<? include('inc/footer.inc'); ?>
Which gives you individual pages -- IF that's what you or the client wants.
Justin French
on 08/08/02 1:23 AM, Alexander Ross (alexross@bleen.net) wrote:
> My problem is this ... my client hasn't the first clue about editing HTML,
> but he can make simple changes in Dreamweaver. So lets say the name of his
> company changes (for example) and the text at the very top of the screen
> which said HAPPY CO. now says HAPPY & SONS. Now this has to change on my
> dynamically created pages as well.
>
> Because of this I can't just add a couple functions to an output.php file
> (which is what I would normally do) nor do I want my client to have to make
> chages to a picemeil html file (i.e. without a body tag or an html tag) from
> within dreamweaver because DW will yell at him.
>
> So my first thought was:
>
>
> <?
> inlude (index.html, line 10 - line 58)
> dynamically do some fun stuff
> incluide (index.html line 234 - line 284)
> ?>
>
> Obviously this isn't real code, but I want to do something like that .. I
> can easily put in a comment or a hidden field to deliniate the start/end of
> each section I want ot include from index.html, (i.e. <!--HERE--> but I
> don't know what to do next.
>
>
>
> "Lowell Allen" <la@lowellallen.com> wrote in message
> news:B975E26B.BCE2%la@lowellallen.com...
>>> From: "Alexander Ross" <alexross@bleen.net>
>>>
>>> Can you include an HTML file up to a certain point. Basically I have a
> .php
>>> which I want to have a static header and a static footer (the same as
> teh
>>> header and footer of everyother page on this site) and then dynamic
> content
>>> in the middle. Is there a way to include each line of html in
> index.html
>>> untill I hit a line with <!--HERE --> (or some other comment?). If so,
> how
>>> can I then do the opposit and include each line of HTML from <!--HERE-->
> to
>>> teh end of the page?
>>>
>> If I understand you correctly, the answer is, "yes, it's very easy". When
>> doing pages that are basically static, I still use PHP for simple
> includes,
>> which allows global changes to the header, menu, footer, etc. to be made
> in
>> just one place. Just create a file called "output_fns.php" and define
>> functions to write the HTML fragments you desire, like:
>>
>> <?
>>
>> function do_html_header($title)
>> {
>> ?>
>> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
>> "http://www.w3.org/TR/html4/loose.dtd">
>> <html>
>> <head>
>> <title><?=$title?></title>
>> </head>
>> <body>
>> <?
>> }
>>
>> function do_footer()
>> {
>> ?>
>> </body>
>> </html>
>> <?
>> }
>>
>> ?>
>>
>> Then do pages like:
>>
>> <?
>> require_once("output_fns.php");
>> do_html_header("Whatever");
>>
>> // more PHP (or HTML)
>>
>> do_footer();
>> ?>
>>
>> --
>> Lowell Allen
>>
>
>