Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 03-28-2011, 10:26 AM
Muffin89 Muffin89 is offline
 
Join Date: Feb 2011
Posts: 4
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Include php file in template

Hi everyone. I have some trouble including a php file in my template, will describe the problem below:

I have a template with an header, a navbar, the forum/content, footer and a fixed right bar. I want to insert this php code(for now) into the right bar:

userbox.php
PHP Code:
<?php
echo '<a href="login.php?$session[sessionurl]do=logout&amp;logouthash=$bbuserinfo[logouthash]">Logga ut</a>';
?>
userbox plugin:
PHP Code:
ob_start();
include(
'userbox.php');
$userboxinsertob_get_contents();
ob_end_clean();
vB_Template::preRegister('footer',array('php_include' => $php_include)); 
Inside the footer template I have made a div that is fixed and I call the plugin with this code:
PHP Code:
{vb:raw userboxinsert
But it doesn't output my desired string.

The HOOK is parse_templates.

When i in the plugin write echo $userboxinsert; the userbox get's inserted but at the top of the screen, so the link works.

Would be very happy if someone could help me with this problem!

--------------- Added [DATE]1301321363[/DATE] at [TIME]1301321363[/TIME] ---------------

I can add that when I turn debug on, the file is included but it doesn't write out any text!
Reply With Quote
  #2  
Old 03-28-2011, 03:48 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This line here is registering a variable named $php_include:
PHP Code:
vB_Template::preRegister('footer',array('php_include' => $php_include)); 
That line would allow you to use this line in the footer template:
HTML Code:
{vb:raw php_include}
If you want to use the variable $userboxinsert, then you need to preregister that variable, not php_include.
PHP Code:
vB_Template::preRegister('footer',array('userboxinsert' => $userboxinsert)); 
Reply With Quote
  #3  
Old 03-29-2011, 07:24 AM
Muffin89 Muffin89 is offline
 
Join Date: Feb 2011
Posts: 4
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you that solved the problem!
Reply With Quote
  #4  
Old 05-26-2012, 05:50 PM
KatieG's Avatar
KatieG KatieG is offline
 
Join Date: Apr 2008
Posts: 77
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I am using (vBulletin 4.0.5 Patch Level 6)

Plugin Code:
Code:
ob_start();
  require_once('/home/XXXX/public_html/Web/Kellys_New_Menu.php');
  $kbar = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('header',array('kellysmenu' => $kellysmenu));
Using Hook: global_start_init_start

To display in header template I tried both below, but I still get no output

Code:
$kellysmenu

{vb:raw kellysmenu}
Can anyone help please
Reply With Quote
  #5  
Old 05-26-2012, 05:53 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Change the preRegister line to:

Code:
vB_Template::preRegister('header',array('kellysmenu' => $kbar));

(or else change the ob_get_contents() line to use $kellysmenu instead of $kbar).
Reply With Quote
  #6  
Old 05-26-2012, 11:23 PM
KatieG's Avatar
KatieG KatieG is offline
 
Join Date: Apr 2008
Posts: 77
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Code:
ob_start();
  require_once('/home/XXXX/public_html/Web/Kellys_New_Menu.php');
  $kellysmenu = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('header',array('kellysmenu' => $kellysmenu));
Using Hook: global_start_init_start

To display in header template I tried both below, but I still get no output
Code:
$kellysmenu
Reply With Quote
  #7  
Old 05-26-2012, 11:49 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try using hook parse_templates. If it still doesn't work, try this as a test:

Code:
ob_start();
  //require_once('/home/XXXX/public_html/Web/Kellys_New_Menu.php');
  $kellysmenu = "This is Kelly's Menu";
ob_end_clean();
vB_Template::preRegister('header',array('kellysmenu' => $kellysmenu));

BTW, you definitely want to use {vb:raw kellysmenu} in the template (assuming you have some version of vbulletin 4).
Reply With Quote
  #8  
Old 05-27-2012, 06:22 AM
KatieG's Avatar
KatieG KatieG is offline
 
Join Date: Apr 2008
Posts: 77
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks

{vb:raw kellysmenu}

worked this morning
Reply With Quote
Reply


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

Forum Jump


All times are GMT. The time now is 02:18 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.04166 seconds
  • Memory Usage 2,242KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (6)bbcode_code
  • (1)bbcode_html
  • (5)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete