vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Include PHP in Template and call Function (https://vborg.vbsupport.ru/showthread.php?t=172185)

DHDesign 03-05-2008 06:38 PM

Include PHP in Template and call Function
 
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?
Code:

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:

PHP Code:

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:

PHP Code:

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:

Code:

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 [DATE]1204764706[/DATE] at [TIME]1204764706[/TIME] ---------------

@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


All times are GMT. The time now is 02:58 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01083 seconds
  • Memory Usage 1,723KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (2)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete