Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Another include problem (simpler) 1

Status
Not open for further replies.

martinb7

Programmer
Jan 5, 2003
235
GB
Hi, this is the same sort as the one before but simpler! pls help, ive been trying for weeks to get it workin but no luck :(
Code:
#tem.template

<table width=&quot;800&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse:collapse&quot;>
	<tr>
		<td width=&quot;100%&quot; height=&quot;100&quot; bgcolor=&quot;#C5DEC6&quot;>Logo here</td>
	</tr>
	<tr>
		<td width=&quot;35%&quot; height=&quot;30&quot; bgcolor=&quot;#0099FF&quot;>[## leftnav ##]</td>
		<td width=&quot;65%&quot; height=&quot;30&quot; bgcolor=&quot;#0000FF&quot;>Main Stuff ^_^</td>
	</tr>
</table>

#dotemplate.php

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd&quot;>[/URL]
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>

<body>
<?php
@(include('navleft.php')) OR die (&quot;bar&quot;);
$logo = doNavLeft();

$pagehtml = implode(&quot;&quot;, file(&quot;tem.template&quot;));           $pagehtml = str_replace(&quot;[## leftnav ##]&quot;, $logo, $pagehtml);
echo($pagehtml);
?>
</body>
</html>

#navleft.php

<?php 
function doNavLeft(){ ?>
<?php echo(date(&quot;d/m/y&quot;)); ?>
<?php } ?>

the date should appear in the light blue box but it doesn't?

any ideas??

URL: thanx


Martin

Computing help and info:

 
the date appears in the top left corner. i'm not sure if this is what you mean. but it works if that is what you are going for


David Kuhn
------------------
 
I think I get now what you are confusing.
Code:
echo(date(&quot;d/m/y&quot;));
The above statement prints the current date into the output stream. An echo statement does that. It does not assign anything into a buffer or so - that's what you expect.

What you want is that the function navLeft() returns the date, not outputs it.

Code:
<?
function navLeft(){
  return(date(&quot;d/m/y&quot;));
?>

That actually will put the result into the variable to which you assign the result of the function.
Code:
$whatever = navLeft();

Get it?
An echo statement is an explicit statement that puts the result of the called function into the output stream.
What you want is to have the information returned implicitly, in a variable of some kind of sort.

This explanation should clear the whole thing up! Ok?
 
thanx that worked a treat, just one more q. what if you want 2 echo something? do u do return(&quot;text&quot;); ??

is that the same for return($var); ??

thanx


Martin

Computing help and info:

 
Yes - given that there is something in the var and the scope is right. You need take into consideration if $var is referred to inside a function: it is the local $var then. You need to globalize it in order to refer to $var outside of the function.

You are following a 2 step process. You temporarily put the information you output into a variable. Then you manipulate a template file by replacing placeholders with the content of the variables.
This is a classic template approach. There are several classes written for such a use of HTML templates. IMO it is the cleanest solution for PHP code separation from HTML/design properties. To follow it trough completely you would not have any HTML in your PHP code.
 
thanx how do you make the variables global?

just one other thing, why isn't the css working properly? is it something 2 do with the <head></head> are in the dotemplate.php page? not the tem2.template??

thanx



Martin

Computing help and info:

 
Code:
<?php
$myVar = 5;

function whatever($dummy){
   global $myVar;
   # now it is the global var
   ...etc...
}
Remember also that $_POST, $_SESSION etc. are superglobal i.e., available in any scope.

I don't get you CSS question. I looked at the HTML produced and it looked fine. Pls. specify what working properly[/] means.
 
i got the CSS working :) thanx 4 all the help!! :)

il get back 2 u if i get any more problems!

have another star ^_^

Regards,


Martin

Computing help and info:

 
how would you go about including a page then??

return(include(&quot;nav.php&quot;)); doesn't work.

how can i do it?

thanx


Martin

Computing help and info:

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top