Go Back   SitePoint Forums > Forum Index > Program Your Site > PHP
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old May 12, 2006, 21:24   #1
ldivinag
SitePoint Evangelist
 
ldivinag's Avatar
 
Join Date: Jan 2005
Location: N37 33* W122 3*
Posts: 413
templates, ECHOing issues...

so i have a html template file something like
PHP Code:

<html>


<head>

</head>
<body>
<?php
include ("left_side_nav.inc");
?>
Hello, my name is ~firstname~    
</body>
</html>
lets call that "template.php"

and then i have a script that goes something like:
PHP Code:

$temp = file ("template.php");

$temp_file = implode ("\n", $temp);

$firstname = "joe";

$temp_file = eregi_replace ("~firstname~", $firstname, $temp_file);

echo (
$temp_file);
problem is that since i ECHO the file, the INCLUDED script (like the left_side_nav.inc) in the PHP section doesnt actually get parsed...

the web page shows correctly BUT NOT the INCLUDEd part. the EREGI_REPLACE does the job...

i hate to make a messy file by combining the two scripts into one...


HELP.......


thanks...
ldivinag is offline   Reply With Quote
Old May 12, 2006, 21:54   #2
Dan Grossman
Follow Me On Twitter: @djg
gold trophysilver trophybronze trophy
SitePoint Award Recipient
 
Dan Grossman's Avatar
 
Join Date: Aug 2000
Location: Philadephia, PA
Posts: 19,741
Choose one convention and stick with it
- Putting PHP code into the template
OR
- Putting identifiers into the template you later replace

For this specific situation:
- Put "$firstname" in the template, and include() the template rather than echoing its contents
OR
- Put "~left_side_nav~" into the template, and replace that with the contents of your nav file
Dan Grossman is online now   Reply With Quote
Old May 12, 2006, 21:59   #3
deregular
SitePoint Zealot
 
deregular's Avatar
 
Join Date: Oct 2004
Location: australia
Posts: 152
Im having trouble with something along the same lines...

I like to keep functions in a seperate file and include the file wherever i may need those functions.

The problem is some of the functions deal with variables that are in the main pages... ie..

"Passing variables to the function that is included, and then spitting out results accordingly.."

PHP is simply not passing the variable to the included function, there has to be a way around this... Can anyone help?
deregular is offline   Reply With Quote
Old May 12, 2006, 22:00   #4
UFTimmy
SitePoint Guru
 
Join Date: Jul 2005
Location: Orlando
Posts: 633
Two solutions.

1. Pass the variables as arguments (prefered).
2. Declare the variables as global within the function.
UFTimmy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 19:39.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved