PDA

View Full Version : Include PHP in Template and call Function


DHDesign
03-05-2008, 06:38 PM
so i get how to include a PHP file in my template using the Plug system, but then the vBulletin manual says that I need to put the contents of the file into a variable like $includedphp and when I want to output its contents, I just call $includedphp from the template.....BUT

my include file is just a bunch of functions and I want the template to be able to access the functions (like footers, headers, stuff generated from the DB)

so in the template i need:

<div id="footer">
<? display_footer(): ?>
</div>

...i need somehting like that work.

any thoughts? thanks!

WhaLberg
03-05-2008, 06:44 PM
Try $myvar = display_footer(); and put $myvar to the template.

DHDesign
03-05-2008, 06:51 PM
so put $myvar = display_footer(); in the hook?

ob_start();
include('path/to/file/cms.php');
$includedphp = ob_get_contents();
$myvar = display_footer();
ob_end_clean();


cause i tried that above, and nothing...a little more detail possibly? thanks for the response though!

Opserty
03-05-2008, 08:13 PM
Try:


ob_start();
include('path/to/file/cms.php');
display_footer();
$myvar = ob_get_contents();
ob_end_clean();

WhaLberg
03-05-2008, 08:58 PM
If your function is echoing or something, you can use the codes below:


function display_footer()
{
$footer = "info here";
return $footer;
}

// and in the other file
$myvar = display_footer();


Can you show us how you have the display_footer() function?

DHDesign
03-05-2008, 09:23 PM
well, its not only the display_footer() function i need, but to answer your question:


function display_footer() {
$footer = mysql_query("SELECT Footer_Text FROM footer_table WHERE F_ID = 1 LIMIT 1");
$footerrow = mysql_fetch_array($footer);
print $footerrow['Footer_Text'];
}


--------------- Added 1204764706 at 1204764706 ---------------

@Opserty: that worked, but what if my include file has more than one function in it and i want to display different things in different areas of the template? say i have display_footer(), display_navigation(), display_header()....each now needs a variable to display in different parts...do i just create three separate hooks?

@WhaLberg: thanks for ur help and responses...the only issue with ur method is that id have to change my functions to return values...these functions are also used on other nonvbulletin pages, so changing them affects other pages too