PDA

View Full Version : Problem with including php content file in header template


jafik2005
08-31-2010, 11:29 AM
Hello,

I tried to include content of php file in my header template using the procedur here http://www.vbulletin.com/docs/html/templates_externalfiles , So i created a php file "test.php" in the root of my website folder which content is :

<?php echo 'hello' ?>

then i created a plugin for the global_start :

ob_start();
include('test.php');
$includedphp = ob_get_contents();
ob_end_clean();

I tried then to insert {vb:raw includedphp} in my header template but nothing appears in my header.

What is for you the problem ?

Thank you in advance for your answer

PS : I tried to change the structur of the path ("/test.php ", "../test.php", Absolute path...) but in vaine
Ps : The use of plugins is activated from the Vbulletin Option

Lynne
08-31-2010, 01:26 PM
You cannot just use any old variable in any template. You need to register them for use (or in this case, preregister it for use). Cellarius wrote a really good article that you may be interested in - [vB4] Rendering templates and registering variables - a short guide (https://vborg.vbsupport.ru/showthread.php?t=228078)

jafik2005
08-31-2010, 05:31 PM
Thank you for your reply,

I readed the post and i did what is asked to do, i created a test.php

<?php


$my_var="hello";

$templater = vB_Template::create('mytemplate');
$templater->register('my_var', $my_var);

$templatevalues['my_insertvar'] = $templater->render();
vB_Template::preRegister('header', $templatevalues);


?>

I created the plugin for global_start

ob_start();
include('testtest.php');
$includedphp = ob_get_contents();
ob_end_clean();

i inserted this code in my header template

{vb:raw my_insertvar}

But nothing happens, any solutions?

Lynne
08-31-2010, 06:10 PM
And what is the contents of your template "mytemplate"? And my_insertvar is not registered, $templatevalues is. So, it's {vb:raw templatevalues.my_insertvar}