By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,137 Members | 2,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,137 IT Pros & Developers. It's quick & easy.

Template Pages with Parse File

P: n/a
Hey,

I have a lot of common things I want to be included on different pages
(i.e. the page title, the header, some buttons and such, etc.).

So I was thinking of putting things like "*PAGETITLE*" into my html
documents, then having a parse.php file that would replace *PAGETITLE*
with the title of the pages.

So I would structure my links like
"http://www.domain.com/parse.php?link=aboutUs.html". It would read in
aboutUs.html, do a string replacement in the appropriate places, then
output what's left.

But something is giving me the feeling that this is a bad idea.

What do you think?

Thanks
iw****@gmail.com

Sep 10 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
IW****@gmail.com wrote:
So I would structure my links like
"http://www.domain.com/parse.php?link=aboutUs.html". It would read in
aboutUs.html, do a string replacement in the appropriate places, then
output what's left.

But something is giving me the feeling that this is a bad idea.

What do you think?


I agree that this is a bad idea. Even when you thoroughly validate the
contents of the link parameter, it reduces the maintainability of your site.

If you want to change the name of the page, you will have to modify all
references. A better solution would be to use a link like:

http://www.domain.com/parse.php?link=about

This way, it's not important how the template file is called and you can
validate the link parameter easily against a list of valid values.
JW


Sep 10 '05 #2

P: n/a
IW****@gmail.com wrote:
So I would structure my links like
"http://www.domain.com/parse.php?link=aboutUs.html". It would read in
aboutUs.html, do a string replacement in the appropriate places, then
output what's left.


You are essentially replicating, in a primitive fashion, the
functionality of the web server and PHP. File look-up is the job of the
web server. Page processing--that's the reason PHP exists in the first
place.

When you have things that happen in multiple places, think function.
What I typically do is have a file that contains the global interface,
with the HTML enclosed inside functions:

<? function PrintHeader($title = "Default title") { ?>
<html>
<head>
<title><?=$title?></title>
.....
<? } ?>
<? function PrintFooter() { ?>
</body>
</html>
<? } ?>

Then I include the file and call the function in each page:

<? require("global.php"); ?>
<? PrintHeader("About Us"); ?>

[ ... page contents ... ]

<? PrintFooter(); ?>

For a more detailed example, go to www.php.net and click on show source.

Sep 11 '05 #3

P: n/a
thanks

Sep 11 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.