PDA

View Full Version : include .php file in templates


Logikos
09-29-2004, 02:18 AM
I've created a .php file that outputs HTML. What i would like to do is ad a $ call in the templates, and have it pull only the HTML file of the .php file i created.

I've tried

if ($html)
{
include('./myfile.php');
}


I even tried lol
eval('$html = "' . include "myfile.php" . '";');

And use $html in the templates but i get nothing. Any ideas what i could use?

Logikos
09-29-2004, 08:39 AM
nvm everyone i got it to work. 6 hours later :p. No time for sleep!

Natch
09-29-2004, 10:04 AM
For those looking for this solution, your myfile.php must end with a return $html; line where $html == your required HTML output...

Brad
09-29-2004, 11:00 AM
I thought about doing a condition that would allow you to do this for html output within templates:

<include="/path/to/file" />

Any intrest, let me know :)

Logikos
09-29-2004, 11:54 AM
Well there is 2 ways to do this. Globaly or just one page.

If your going to do one page like i needed. On my forumhome page. I just opened index.php and added the following line just before the navbar and header veriables.


ob_start();

All the php code you want here

$html = ob_get_contents();
ob_end_clean();


Then i just added $html in my forumhome template and it worked perfect. For those who need it on all pages. Just add the above code in your php_include_start template.