View Full Version : Getting include statements to work in the forum templates?
Gutspiller
09-07-2002, 04:45 AM
I have looked at the following threads:
https://vborg.vbsupport.ru/showthread.php?threadid=42328&highlight=includes
https://vborg.vbsupport.ru/showthread.php?threadid=39448&highlight=includes
https://vborg.vbsupport.ru/showthread.php?threadid=36491&highlight=includes
After reading those, I still don't know how to do it and get it to work. Can somebody give me some help on how to get a php file to be included at the top of each page of the forum?
Any help is appreciated.
Thanks!
Logician
09-07-2002, 07:31 AM
You can add its contents into your "phpinclude" template
Gutspiller
09-07-2002, 05:40 PM
Originally posted by Logician
You can add its contents into your "phpinclude" template
What exactly do you mean? You mean just including the include statement in the phpinclude, or do you mean actually including the contents of the file I'm trying to include? It's a big include file. Probably a good 250+ lines of code. :confused:
Logician
09-08-2002, 04:23 AM
I dont know if "include" or "require" would work (I guess so though) so I meant adding the code directly in phpheader template. But it doesnt matter if you include or require either because tecnically they are not different then adding the code directly. If you have some PHP knowledge you can also convert the program to a "function", add it to functions.php and call it inside the template or global.php either..
If you want the program to be parsed you have to use either way even if it's a long program. But being a long program doesnt effect the performance: everytime your "any" vbulletin script is parsed "functions.php" with over 2500 lines of code is included in every run.. ;)
Gutspiller
09-09-2002, 06:34 PM
I've tried to include the file that has the code in it, but it does work. It sounds like your saying that should work. Did I do it wrong? I just used the normal include statement:
<? include("blah.php"); ?>
What am I doing wrong?
Logician
09-10-2002, 12:01 PM
I guessed so but if it's not working then it means my guess was wrong. So use the other methods.. You dont need to insist on including because as I said before inclusion is not different than adding the entire code inside your template.. In fact it is what your file does when it runs if you made an inclusion..
Gutspiller
09-12-2002, 11:46 PM
Originally posted by Logician
I guessed so but if it's not working then it means my guess was wrong. So use the other methods.. You dont need to insist on including because as I said before inclusion is not different than adding the entire code inside your template.. In fact it is what your file does when it runs if you made an inclusion..
What other "methods" are there? If including is the same as putting code in the files themselves, then that wont work either.
What else can I try? I could do a lot of cool stuff if I can get the include statement to work. I really need something that will make it work, or will work the same way because I have other files that are outputting their data to a file and I need to tell my forums to grab that info and slap it on the pages.
Any ideas?
Logician
09-13-2002, 07:13 AM
Originally posted by Gutspiller
What other "methods" are there?
I have mentioned them in my previous message. Here are they again:
1- Add the entire code to phpinclude. As I said before you dont need to be scared because technically it's no different than adding a include("file.php") to your phpinclude template.
2- Convert your code to a function and add it at the end of inside function.php. Then you can call it as
yourfunction();
inside phpinclude template or global.php.
3- Add you code to global.php. It also runs everytime any vb scripts runs, just like phpinclude template.Therefore you can try to add either the include statement or the entire code to global.php as well..
NTLDR
09-13-2002, 07:52 PM
Originally posted by Gutspiller
I've tried to include the file that has the code in it, but it does work. It sounds like your saying that should work. Did I do it wrong? I just used the normal include statement:
<? include("blah.php"); ?>
What am I doing wrong?
Just put:
include('./blah.php');
Having the <?php and ?> tags in there is messing it up. This does work as vBstats uses this method.
Gutspiller
09-13-2002, 10:14 PM
NTLDR that seemed to work, but it puts it at the very top of the page. Is there anyway to get it so I can do stuff with it. Like have stuff above it, etc. So that it's just another thing I can call up by doing something like "$stuff"?
I didn't really want it at the very top, but it's a step in the right direction.
Any ideas?
futureal
09-13-2002, 10:22 PM
You could put something like $stuff = something; in global.php and then use $stuff in a template anywhere on the site.
Gutspiller
09-13-2002, 10:26 PM
Originally posted by futureal
You could put something like $stuff = something; in global.php and then use $stuff in a template anywhere on the site.
Is that the actual code?
so if I put
$shortnews = include("shortnews.php");
then in my templates whenever I put in $shortnews it would call the shortnews.php file?
I just wanted to make sure that was the exact code or if you were putting more emphasis on "like"?
This is going to be KICK ASS! :D
futureal
09-14-2002, 02:19 AM
Sort of, but not exactly.
In your global.php file, you need to add a line like this:
$something = eval("include(\"somefile.php\");");
The eval() function evaluates a line of code "on-demand" rather than every time the script runs. In other words, if you did it your way (without eval) then it would just display the contents of the included PHP file at the top of every page -- I don't believe include() returns a value.
Anyway, then in your templates, wherever you add $something, you will get the contents of the PHP file.
This is essentially the third option that Logician gave:
3- Add you code to global.php. It also runs everytime any vb scripts runs, just like phpinclude template.Therefore you can try to add either the include statement or the entire code to global.php as well..
And yes, it works; I just tested it on one of my sites. Have fun.
Gutspiller
09-14-2002, 07:39 AM
That seems to do the same thing. I didn't even call it in the template. As soon as I put it in the global file it called it and put it above the header.
Anything else? :(
futureal
09-14-2002, 04:29 PM
OK, for some reason I was thinking that your included file would be performing some sort of function rather than just outputting data.
I thought about it some more, and I'm not sure how you would get the output "on demand" as you suggest, without adding it to the vBulletin code -- assuming that the PHP file you want to include echoes something back.
Why not just edit the files so that they "store" their output in a variable, then put the file in the global.php as I suggested (or the phpinclude template as Logician suggested) and then just use that variable where you need the output?
I can't think of any other way to do it. I think that to achieve what you're trying to do, you're going to need to work with the code one way or another.
Gutspiller
09-14-2002, 04:35 PM
Originally posted by futureal
OK, for some reason I was thinking that your included file would be performing some sort of function rather than just outputting data.
I thought about it some more, and I'm not sure how you would get the output "on demand" as you suggest, without adding it to the vBulletin code -- assuming that the PHP file you want to include echoes something back.
Why not just edit the files so that they "store" their output in a variable, then put the file in the global.php as I suggested (or the phpinclude template as Logician suggested) and then just use that variable where you need the output?
I can't think of any other way to do it. I think that to achieve what you're trying to do, you're going to need to work with the code one way or another.
Can one of you help me with doing that? I'm a noob when it comes to rewriting the code, etc. Can anybody give me instructions on what I need to do inorder to get this to work? :ermm:
Gutspiller
01-25-2003, 06:42 PM
bump!
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.