Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Instead of using headers/footers in php, can I...

Contributor ,
Jan 03, 2010 Jan 03, 2010

Hi,

Currently, I am using PHP includes to assemble my page elements together. The header gets its own include, the content, and the footer.

Only problem with this scenario is that things opened in the header -- like tables, for instance -- aren't closed until the footer. As you might imagine, this makes editing the header OR footer a very daunting process.

Would it, instead, be possible to fetch -- as an include -- the entire site template... and specify somewhere inside where the content will be included? This way, when I need to modify the template, it'll hold up together in front of me as I am working on it (and not just contain opening elements that are never closed, or vice versa).

TOPICS
Server side applications
863
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 03, 2010 Jan 03, 2010

Sure, like this:

<!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>My Page</title>
</head>
<body>
<?php include('header.php'); ?>
<?php include('content.php'); ?>
<?php include('footer.php'); ?>
</body>
</html>

Ken Ford

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 03, 2010 Jan 03, 2010

Actually, you just described word-for-word how I'm already doing it (see first paragraph of the OP).

If you read the rest of the OP more closely, you'll see that you didn't really understand what it is I'm asking (or I wasn't as clear as I thought I was).

"Header" opens elements that aren't closed until "footer". As such, header isn't editable in any practical way inside Dreamweaver (tables get opened but never closed, for instance).

I proposed having the whole template in a single file (so what's opened get closed), with an insert telling the template where the editable area is.

Kind of like how Dreamweaver uses Templates right now, but using PHP so the actual template code is stored only in 1 file, and would require only a single upload after editing.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 03, 2010 Jan 03, 2010

You would just have to set up the page to do what you want.

Without seeing any code, I really can't help, sorry.

Ken Ford

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 03, 2010 Jan 03, 2010

No problem. Here...

Hypothetical Example

header.php :

<table>

<tr>

<td>

content.php :

Hello.

footer.php :

</td>

</tr>

</table>

index.php :

<?php include('header.php'); ?>

<?php include('content.php'); ?>

<?php include('footer.php'); ?>

Or, alternately :

index.php :

<?php include('header.php'); ?>
Hello.
<?php include('footer.php'); ?>

In the above example -- which requires a minimum of 3 files, and is the way most people use php includes -- you cannot easily edit the header or footer using the Dreamweaver design view, simply because you've got tags opening that are never closed (and vice versa) in those individual files (header.php, footer.php).

To be even more clear, header.php needs those </td>, </tr> and </table> tags to be viewed properly in design view. On its own, it doesn't have them. They're in footer.php.

Meanwhile, footer.php needs those <table>, <tr> and <td> tags to be viewed properly in design view. On its own, it doesn't have them either. They're in header.php.

Only once the page is assembled on the server side can it be properly served to the end user, where all opened tags are appropriately closed, and vice versa... with the content sandwiched in-between.

This is how we all traditionally use PHP includes.

* * * * * * * * * * * * * * * * * * * * * * * * * *

But what I'd *like* to do, is this :

template.php :

<table>
<tr>
<td>

$_SOMEKIND OF STRING (telling the template where to insert the content)

</td>

</tr>

</table>

content.php

$_FETCH TEMPLATE (/template.php)

Hello.

In the above example, only 2 files are required. There isn't even a need for a wrapping file including all the various elements.

Now obviously, I don't know enough about PHP to even begin to know how one would call these strings, but we're getting ahead of ourselves. I'd first like to know if it's even CONCEIVABLE that PHP could be used this way.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 05, 2010 Jan 05, 2010

Guess not.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 06, 2010 Jan 06, 2010
LATEST

It is possible, but not if you want to be able to edit things in Design view.

One thing you could try is putting the opening and closing table tags in the main page, and then using your includes. However, splitting a single HTML block into different include files is courting trouble. If one of those include files is corrupted, the whole page just falls apart. It also makes it difficult to keep track of opening and closing tags.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines