Wrapper file that contains header, navs, and footer

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
pbritten
Forum Newbie
Posts: 13
Joined: Wed Mar 24, 2004 9:24 am
Location: State College, Pennsylvania, USA

Wrapper file that contains header, navs, and footer

Post by pbritten »

Hello, All!

Is it possible to create one wrapper file that can contain and place the header, navs, footer, and any other repeating pieces of code? Presently, I build sites using the following structure:

<?php
require "header.php";
require "navs.php";
require "title.php";
?>
Page specific content goes here.
<?php require "footer.php"; ?>

After a friend showed me the one streamlined wrapper file he uses when he develops ColdFusion pages, the multiple-require structure above seemed unwieldy by comparison. I wonder if PHP has the same ability.

Thank you for your help!

Pat
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

:arrow: [devnet]template[/devnet]
tomtomtom
Forum Newbie
Posts: 8
Joined: Tue Dec 28, 2004 12:39 pm

Post by tomtomtom »

It's possible to build a site around a single index.php file, using query strings to pass page information.

index.php would include the entire template and all shared functions, and would do a conditional include of whatever page was requested via query string.

e.g. index.php?page=hello (or even index.php?hello, using some trickery), could cause the page hello.php to be included and parsed. The hello.php file would never be accessed directly (and often you'd want to explicitly prevent that).
pbritten
Forum Newbie
Posts: 13
Joined: Wed Mar 24, 2004 9:24 am
Location: State College, Pennsylvania, USA

Post by pbritten »

Interesting, Tomtomtom.

Using your idea, how would the user be able to bookmark the page?

Pat
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

that's a regular url.. they can bookmark it all they want... unless it's in a frame, in which case, they'll likely bookmark the toplevel page.
pbritten
Forum Newbie
Posts: 13
Joined: Wed Mar 24, 2004 9:24 am
Location: State College, Pennsylvania, USA

Post by pbritten »

Feyd,

Thank you for the link to "templates". I must admit that I'm slower than the average bear with these things. I did indeed read through many threads on this wonderful site, but couldn't interpret them as the answer. Perhaps it's because the necessary code to do this is much different than the level of PHP that I'm currently writing.

Might you know of a book or resource that provides a step-by-step guide to building the wrapper concept?

Thank you very much!

Pat
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

McGruff can probably better point you, as I only have 1 book on php, which is all advanced stuff... However, I can recommend the design pattern books
pbritten
Forum Newbie
Posts: 13
Joined: Wed Mar 24, 2004 9:24 am
Location: State College, Pennsylvania, USA

Post by pbritten »

Thank you very much for sharing, Feyd. A quick read through the introduction and chapter 1 shows me that I have much to learn! :)

Pat
Post Reply