PDA

View Full Version : Declaring and Using PHP variables


zxb
05-26-2001, 10:41 AM
Lets say I created a php function xyz() and subsequently assigns its output to a variable $abc.

Now, I want $abc's value to appear in the template named "head". Apparently, simply editing the template and adding $abc to the desired location in the template does not produce the desired final output. The value of $abc is not displayed.

The template "head" itself contains VBB's original program variables like "$bbtitle" and these are substituted correctly. So how do I make my custom var "$abc" do that?

Thanks in advance.

The Snake
05-26-2001, 11:20 AM
did u create the function xyz() in the same file where you are calling it from?
otherwise you should require the file the function is in, for example xyz.php by adding this line into the head template:

require("xyz.php")

tubedogg
05-26-2001, 08:00 PM
PHP is not parsed in the templates, except for the phpinclude template. You will either have to add it to that (but remember to assign it to a variable, don't output it directly) or put it in global.php around where it declares the header and footer.

zxb
05-27-2001, 06:40 AM
Thanks for the replies.

tubedogg, I'm trying to do what you suggested:

1) in phpinclude template, I've added the following lines:
include("myhacklib.inc"); // my custom codes
$myvar = myfunction(.....);

2) Added $myvar into the desired template and everything gets parsed and displayed as desired.

What I'm concerned about is whether there'll be any performance issues involved cos the stuff in "phpinclude" template is probably applied to all pages in the BB. So if I've functions that I only require in say, the BB home page, is there any other place I can place it and still get the same results?

JamesUS
05-27-2001, 08:07 AM
You would then need to put it in the actual PHP file of the page, eg for forumhome it needs to go somewhere in index.php