PDA

View Full Version : Include php file in template


Muffin89
03-28-2011, 10:26 AM
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
echo '<a href="login.php?$session[sessionurl]do=logout&amp;logouthash=$bbuserinfo[logouthash]">Logga ut</a>';
?>

userbox plugin:

ob_start();
include('userbox.php');
$userboxinsert= ob_get_contents();
ob_end_clean();
vB_Template::preRegister('footer',array('php_inclu de' => $php_include));

Inside the footer template I have made a div that is fixed and I call the plugin with this 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 1301321363 at 1301321363 ---------------

I can add that when I turn debug on, the file is included but it doesn't write out any text!

Lynne
03-28-2011, 03:48 PM
This line here is registering a variable named $php_include:
vB_Template::preRegister('footer',array('php_inclu de' => $php_include));That line would allow you to use this line in the footer template:
{vb:raw php_include} If you want to use the variable $userboxinsert, then you need to preregister that variable, not php_include.
vB_Template::preRegister('footer',array('userboxin sert' => $userboxinsert));

Muffin89
03-29-2011, 07:24 AM
Thank you that solved the problem!

KatieG
05-26-2012, 05:50 PM
I am using (vBulletin 4.0.5 Patch Level 6)

Plugin 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('kellysmen u' => $kellysmenu));


Using Hook: global_start_init_start

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

$kellysmenu

{vb:raw kellysmenu}

Can anyone help please

kh99
05-26-2012, 05:53 PM
Change the preRegister line to:

vB_Template::preRegister('header',array('kellysmen u' => $kbar));


(or else change the ob_get_contents() line to use $kellysmenu instead of $kbar).

KatieG
05-26-2012, 11:23 PM
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('kellysmen u' => $kellysmenu));

Using Hook: global_start_init_start

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

kh99
05-26-2012, 11:49 PM
Try using hook parse_templates. If it still doesn't work, try this as a test:

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('kellysmen u' => $kellysmenu));


BTW, you definitely want to use {vb:raw kellysmenu} in the template (assuming you have some version of vbulletin 4).

KatieG
05-27-2012, 06:22 AM
Thanks

{vb:raw kellysmenu}

worked this morning