Page 1 of 1

variable? $foo = include("file.php"); Can you do

Posted: Thu Sep 12, 2002 3:02 pm
by jmandango
Is this possible?

I am trying to have a template based site and wan't to have a layout.php page which includes the majority of html, formatting, etc. and then content pages which include the variables. I have everything working but when I try to have a variable that has an include function it returns the included file at the top of the resulting webpage rather than in the spot where the variable resides. Here is the code:

Content Code

Code: Select all

<?php

//this is a the content page that uses the Template class

require_once "Template.class"; //Include the class
$page = new HtmlTemplate ("layout.php"); //create an instance

$page->SetParameter("PAGE_TITLE","This is the title");

$sub = '<td class="graybodyBold">THE COURSE</td>';

$nav = '<a href="1.php">ONE</a><a href="2.php">TWO</a>';

$content = '<td class="text">Some body copy.</td>';
				  
$menu = include("menu.php");

$page->SetParameter ("SUB_TITLE", $sub); //set the subtitle
$page->SetParameter ("PAGE_CONTENT", $content); //set the content
$page->SetParameter ("NAVIGATION_LINKS", $nav); //set the navigation
$page->SetParameter("MENU", $menu);

$page->CreatePage(); //send the page to the browser

?>
Template Code

Code: Select all

<html>
<head>
<title>&#123;PAGE_TITLE&#125;</title>
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <!-- this is the menus residing place -->
	<td>&#123;MENU&#125;&#1111;i]&#1111;color=red]This should be where the menu shows up&#1111;/color]&#1111;/i]</td>etc.

---html-----

<!-- sub navigation html goes here -->
&#123;NAVIGATION_LINKS&#125;

---html---		 

	<!-- this is the subtitle -->
	&#123;SUB_TITLE&#125;
             
 <!-- this is where the content goeth -->
	&#123;PAGE_CONTENT&#125;
              
<!-- this is where the footer goeth -->
&#123;PAGE_FOOTER&#125;
</body>
</html>
hope this makes sense. Please help, again. Thanks much.

Posted: Thu Sep 12, 2002 3:54 pm
by jason
No, basically you are going to have to use fopen(), fread() and fclose() to get the file contents.

That, or file() and implode()