all right, i know very little about php, so my knowledge is very sparse and scattered.. but here's the scenario. i have a very simple global page layout template system powered by php. it works like this: i have one file called global_template.inc containing parts of the site layout with variable values in it. simplified example of the file global_template.inc:
<?function commonHeader($pagetitle, $yearmonth)
{ ?>
<html>
<html>
<head>
<title><?echo $pagetitle;?></title>
</head>
<body>
<a href="<?echo $yearmonth;?>/test.php3">Test Link in Header</a>
<? }
function commonFooter($yearmonth) { ?>
<a href="<?echo $yearmonth;?>/test.php">Test Link in Footer</a>
</body>
</html>
<? } ?>
and then this would be a simple example of one of my actual pages:
<? require("global_template.inc");
commonHeader("This is the page title","2003/01"); ?>
<p>This is my page body.</p>
<? commonFooter("2003/01"); ?>
All right. Please notice the "yearmonth" variable and how both the commonHeader and commonFooter have it in global_template.inc, and how i have to declare it twice in one of the actual pages. Is there any way to get both commonHeader and commonFooter to SHARE one declaration of this variable, so I only have to enter it once and have them both take it happily?
Question
sdkaneda
all right, i know very little about php, so my knowledge is very sparse and scattered.. but here's the scenario. i have a very simple global page layout template system powered by php. it works like this: i have one file called global_template.inc containing parts of the site layout with variable values in it. simplified example of the file global_template.inc:
<?function commonHeader($pagetitle, $yearmonth) { ?> <html> <html> <head> <title><?echo $pagetitle;?></title> </head> <body> <a href="<?echo $yearmonth;?>/test.php3">Test Link in Header</a> <? } function commonFooter($yearmonth) { ?> <a href="<?echo $yearmonth;?>/test.php">Test Link in Footer</a> </body> </html> <? } ?>and then this would be a simple example of one of my actual pages:
<? require("global_template.inc"); commonHeader("This is the page title","2003/01"); ?> <p>This is my page body.</p> <? commonFooter("2003/01"); ?>All right. Please notice the "yearmonth" variable and how both the commonHeader and commonFooter have it in global_template.inc, and how i have to declare it twice in one of the actual pages. Is there any way to get both commonHeader and commonFooter to SHARE one declaration of this variable, so I only have to enter it once and have them both take it happily?
Link to comment
Share on other sites
9 answers to this question
Recommended Posts