![]() |
Problem adding and using global vars of my own
Hi,
I'm using vB 3.6.8 patch level 2. I want to add variables for use in any and all templates. To do so, I've created a mytxtfile.txt file with the desired content (in HTML), and added the following lines at the end of global.php: $mytxtfile = 'mytxtfile.txt'; $mycontent = file_get_contents($mytxtfile); Then, I added $mycontent inside templates, by writing $mycontent in the template editor. The problem is that this works with some templates, but not with others. For example, it worked with navbar and with a new template I made, but not with postbit. 1. Why? 2. Is there a better way to do this? 3. Where are custom templates (like the new one I made) stored? Any help will be appreciated, Thank you, R. |
Add the following line to your plugin:
PHP Code:
|
First, thank you. Now, I'm a total newbie. Where is my plugin (do I even have one?) and how do I add this line to it?
Quote:
|
Hmm now see that you don't use a plugin but instead edit global.php (bad choice in my view). Just add it in global.php then, just above the 2 lines you already added.
|
Thank you again, Marco.
- Is the global command a vB function? - What is the better way to do this, in your experience? Quote:
|
"global" is a standard PHP command that will set the variable in the global scope.
I would not do any code edits, but just put this code into a plugin, probably using the 'global_start' hook location. |
I've tried this - but it still doesn't work with the postbit template. Why could that be?
Quote:
To anyone who's had the same type of problem, I've found a different solution. I am ignorant as to why this worked and the other way didn't, but here it is: Instead of referencing $mycontent directly, I called it through $GLOBALS, which is a superglobal. It is an array of all global-scope variables, the keys of which are the variables' names. Therefore, I was able to call $mycontent by writing $GLOBALS[mycontent]. This page helped me find this solution. |
All times are GMT. The time now is 12:17 PM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|