Forum Moderators: coopster

Message Too Old, No Replies

eztemplate

I've started but no cigar!

         

russgri

5:16 am on Jul 29, 2003 (gmt 0)

10+ Year Member



I haven't implement the fopen correctly...er...at all.
<br />
<b>Warning</b>: fopen(topnav.inc): failed to open stream: No such file or directory in <b>/home/httpd/vhosts/mysite.com/httpdocs/test.php</b> on line <b>43</b><br />
<br />
Here is the code:

<?php
/*These are the dynamic values that we want to insert into our template(s).*/
/*head1.inc contains Doc statement contents of <html>and Link Rels/imports thru </head>*/
$output->head = file_get('includes/head.inc');
/*logo.inc contains all logo text and images */
$output->body = file_get('includes/logo.inc');
/*topnav.inc*/
$output->body = file_get('topnav.inc');
$output->body = file_get('leftnav.html');
?>
/*Body content begins*/
<div id="content">
<h1>Hello World</h1>
</div>
<div id="right">
<!-- Content of right column -->
</div>
<?php
$output->body = file_get('includes/footer.inc');
?>
<?php
/*
This is how we merge the $output variable with the various includes
*/
echo merge_template(file_get('main_template.html'),$output);

[b]/* I am stalled at this point...assuming that I am correct at this point.*/[/b]
/****************************************************
*
* Function library for using basic templates
*
*****************************************************/

/*
*file_get()
*
*Load file contents and return as a single variable
*/

function file_get($path)
{
$file = '';
$fp = fopen($path,'r');
while(!feof($fp))
$file .= fgets($fp,4098);
return $file;
}

/*
*merge_template()
*
*Merge main_template with values stored in $output object
*(note: template is always loaded in the form of a variable)
*/

function merge_template($content,$output)
{

/* Convert all the php variables to their dynamic values */
eval("\$content = \"" . str_replace("\"","\\\"",$content) . "\";");

/* Return the merged main_template from this function */
return $content;
}
?>

MWpro

5:43 am on Jul 29, 2003 (gmt 0)

10+ Year Member



I can't help you with your problem, but if all you're trying to do is include identical content on your pages, I think you're definitely taking the wrong approach and are making things much more complicated than they need to be.

I would suggest looking into doing this same thing with the include command and heredoc syntax.

Example

/*include.php*/
<?
$top = <<<END
anything you have in head.inc
END;
$topnav = <<<END
anything you have in topnav.inc
END;
etc..
?>

then on your page all you do is this:
<?
include("include.php");
echo $top;
echo $topnav;
etc..
?>
Content stuff here
<?
echo footer
?>

Much easier in my opinion.

russgri

9:36 pm on Jul 30, 2003 (gmt 0)

10+ Year Member



Thanks MWpro,

Quote


I would suggest looking into doing this same thing with the include command and heredoc syntax.
Example
/*include.php*/
<?
$top = <<<END
anything you have in head.inc
END;
$topnav = <<<END
anything you have in topnav.inc
END;
etc..
?>
then on your page all you do is this:
<?
include("include.php");
echo $top;
echo $topnav;
etc..
?>
Content stuff here
<?
echo footer
?>
Much easier in my opinion.

Here is some code...improper syntax...please comment.

<?php
/*this does not work
$head = <<<END aainc-head.inc END;
?>
<?php
/*this does not work
$head = <<<END
aainc-head.inc
END;
?>


Here is the index.php code


<?php
include("include.php");
echo $head;
echo $logo;
echo $topnav;
echo $leftnav;
echo $right;
?>

Here is the error code:
Parse error: parse error, unexpected T_SL in /home/httpd/vhosts/mysite.com/httpdocs/xarahost/include.php on line 2

MWpro

11:23 pm on Jul 30, 2003 (gmt 0)

10+ Year Member



I meant copy all the stuff in that file to the include file

If aainc-head.inc contains this:


<html>
<head>
<title></title>
etc..
</head>

Then you would put this in include.php:


$head = <<<END
<html>
<head>
<title></title>
etc..
</head>
END;

russgri

7:21 pm on Jul 31, 2003 (gmt 0)

10+ Year Member




Thanks MWpro


Still working on syntax.
I have checked php_net.
Searching for 'heredoc syntax'...
Nothing specific found ...except whitespace warning and
end of line info...that probably does not apply.
---------
[b]
/* error in browser window source code */
<br />
<b>Parse error</b>: parse error, unexpected T_SL in <b>/home/httpd/vhosts/mysite.com/httpdocs/xarahost/include.php</b> on line <b>13</b><br />

Hello World
---------
/* error in browser window */
Parse error: parse error, unexpected T_SL in /home/httpd/vhosts/mysite.com/httpdocs/xarahost/include1.php on line 13
Hello World

[b]
/* include.php */
[/b]

<?php
$html = <<<END
<html>
<head>
<title>Sportsmen Afield&nbsp;&gt;
<?php
echo($title);
?></title>
</head>
END;
?>
<?php
$body = <<<END //This is line 13
<body>
echo Hello World
END;
?>
<?php
$footer = <<<END
Copyright &copy; 1998-2002 - Mysite.Com/Mysitename All Rights Reserved -
<a href="mailto:info@sportsmenafield.com"style="color:beige">Webmaster</a>
</body></html>
END;
?>

[b]
/**** index.php***/
[/b]
<?php
include("include.php");
echo $html;
echo $body;
?>
Hello World
<?
echo $footer;
?>