vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Parse PHP in a Template (https://vborg.vbsupport.ru/showthread.php?t=62129)

TLCanna 03-03-2004 12:58 PM

Parse PHP in a Template
 
I have recently upgraded to VB3, my old boards had a banner rotator.php that was included in my header template.

My Problem:
When I do a PHP include like so <? include ("rotator.php");?> it displays the text on the screen. It doesn't actually parse the code and randomly rotate my banners.

Is there a command to force the template to parse the php code?

NTLDR 03-03-2004 01:01 PM

You can only parse PHP code in the phpinclude_start and phpinclude_end templates.

TLCanna 03-03-2004 01:03 PM

Do you indcate it to be parsed by a PHP command or what?

NTLDR 03-03-2004 01:10 PM

You just place your PHP in the template as if it was a .php file.

PHP Code:

include('rotator.php'); 


TLCanna 03-03-2004 01:38 PM

Thanks NTLDR... That worked, but now I have a second question. While reading the help screen for phpinclude_start.... It says You can enter PHP code here. The phpinclude_start template is evaluated at the beginning of page execution and can be used for putting things into templates.

So it sounds like I can now include the phpinclude_start to any template and it can be be displayed accordingly.

My questions is, what is the syntax for inserting to a template, should I say include or drop it in as a variable in the template.

Anna

PS... Let me apologize in advance for dumb questions, my technical skills are green at best.

:)

NTLDR 03-03-2004 01:55 PM

If you follow the example in there:

PHP Code:

// Example of how to include a seperate file: 
ob_start();  
require(
"yourheader.html"); 
$headercontent ob_get_contents();  
ob_end_clean(); 

You could then put $headercontent (which should work in most cases, some templates will require $GLOBALS[headercontent]) will place the HTML found in yourheader.html where you have placed the variable.

ixian 03-06-2004 04:39 AM

I have a similar problem, but I'm having some difficulty.

The problem is, I'm trying to get a php script that makes it's own call to a different database on the same server, called "center".

The phpinclude_start statement looks like this:
Code:

ob_start();
require_once ('../center/activity.php');
$activity1 = ob_get_contents();
ob_end_clean();

But when that happens, I get database errors on my forums, saying it can't find variable this, variable that - it looks like once it switches to my "center" database it doesn't switch back to the vbulletin db.

I tried using

chdir("$/var/www/html/forums");

After the above include, but that did nothing.

Anyone have any ideas? I'm sure I'm doing something wrong here. I tried using "include" and "require" above as well.

NTLDR 03-06-2004 06:37 PM

Whats the code in center.php? If it doesn't echo/print etc anything directly out then you just need the require_once() part in the php_include_start template.

ixian 03-06-2004 08:28 PM

It does echo/print stuff out, which is the problem.

I finally solved this by moving the table it uses over to the vbulletin database, and using it instead. It's a small, simple table with 3 rows and not a lot of information, so load isn't an issue, and it works now.

Kind of in-elegant for other types of php scripts though, but what can you do.


All times are GMT. The time now is 10:00 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.01377 seconds
  • Memory Usage 1,729KB
  • 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
  • (1)bbcode_code_printable
  • (2)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)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