vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Include php page (https://vborg.vbsupport.ru/showthread.php?t=228056)

Silver89 11-15-2009 10:05 PM

Include php page
 
I'm trying to include a php file with the following code as documented on the vBulletin pages, my plugin is setup as:

PHP Code:

ob_start();
  include(
'/header.php');
  
$globalHeader ob_get_contents();
ob_end_clean(); 

I then write - $globalHeader - in the header file where I want this include to appear? I have it setup with the host location of global_start but at the moment it just shows $globalHeader on screen and I'm not sure what's wrong?

Many Thanks

kh99 11-15-2009 10:22 PM

nvm

Dismounted 11-16-2009 03:53 AM

The way variables are used in templates has changed in vBulletin 4. You must register any variables before using them and address them like so: {vb:raw globalHeader}
PHP Code:

$preRegister['globalHeader'] = $globalHeader;
vB_Template::preRegister('header'$preRegister); 


Silver89 11-16-2009 04:05 AM

Okay I have managed to get the php include for 4.0 working with the following code:

Template:
Code:

{vb:raw globalHeader}

Plugin:
PHP Code:

ob_start();
  include(
"../header.php");
  
$globalHeader ob_get_contents();
ob_end_clean();

$preRegister['globalHeader'] = $globalHeader;
vB_Template::preRegister('header'$preRegister); 


However what I really want to do is basically create my own custom template page, the problem with this current include is that the vb code inside ../header.php is just printed instead of being executed, what can I do to fix this?

Many Thanks

cory_booth 11-16-2009 08:34 AM

Along the same lines....

What would be the easiest way to include php pages in the CMS?
For example, I run HamWeather on my site. PReviosuly - using vbAdvanced - I made some templates that called in php files to display the weather. Can I do the same via CMS?

Something like this for example:

PHP Code:

<?php 

$doPrintNWS 
false;

require(
"/home1/mysite/public_html/modules/advforecast.php"); ?> 

<html>

<body style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; background-color:#F5F5FF">

<table style="font-size:9px;"> 

<tr align="center" valign="top">

<?php print "<td>$forecasticons[0]</td><td>$forecasticons[1]</td><td>$forecasticons[2]</td><td>$forecasticons[3]</td><td>$forecasticons[4]</td><td>$forecasticons[5]</td><td>$forecasticons[6]</td><td>$forecasticons[7]</td>\n"?> 

</tr> 

<tr align="center" valign="top">

<?php print "<td>$forecasttemp[0]</td><td>$forecasttemp[1]</td><td>$forecasttemp[2]</td><td>$forecasttemp[3]</td><td>$forecasttemp[4]</td><td>$forecasttemp[5]</td><td>$forecasttemp[6]</td><td>$forecasttemp[7]</td>\n"?> 

</tr>

</table> 

</body>

</html>


Red Spider 12-05-2009 02:50 PM

Quote:

Originally Posted by Silver89 (Post 1915044)
Okay I have managed to get the php include for 4.0 working with the following code:

Template:
Code:

{vb:raw globalHeader}

Plugin:
PHP Code:

ob_start();
  include(
"../header.php");
  
$globalHeader ob_get_contents();
ob_end_clean();

$preRegister['globalHeader'] = $globalHeader;
vB_Template::preRegister('header'$preRegister); 


copied word for word and just changed the variable name - but wont work - any ideas?

Lynne 12-05-2009 04:15 PM

PHP Code:

vB_Template::preRegister('header', array('globalHeader' => $globalHeader)); 


Red Spider 12-05-2009 04:33 PM

Quote:

Originally Posted by Lynne (Post 1925775)
PHP Code:

vB_Template::preRegister('header', array('globalHeader' => $globalHeader)); 


thanks Lynne, but that doesnt work either :'(

Lynne 12-05-2009 04:49 PM

It doesn't help when you just say something doesn't work. The best thing to do is say "This is my exact code in the ____ hook location {post code} and this is exactly what I have in my template {post about five lines above and below added code also}."

My guess would be you don't have the correct hook location. Did you look in the code to see where the header is rendered? And then looked above the code to pick a hook above there? Or did you just randomly pick a hook location?

rudejason 12-07-2009 01:34 PM

Quote:

Originally Posted by Red Spider (Post 1925734)
copied word for word and just changed the variable name - but wont work - any ideas?

THANK YOU SO MUCH!!!! i have looked for about 3 hrs total on how to make this work!
All i could find on this board was a link to the manual. That guy that always posts the link and says stuff about people must not like the manual needs to up date it with the code on how to use the variables in the template. I bet then he would no longer need to post the link.

Thanks again!


All times are GMT. The time now is 07:25 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.01224 seconds
  • Memory Usage 1,759KB
  • 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
  • (7)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete