vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Problem adding and using global vars of my own (https://vborg.vbsupport.ru/showthread.php?t=180118)

raztrip 05-22-2008 10:40 AM

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.

Marco van Herwaarden 05-22-2008 10:50 AM

Add the following line to your plugin:

PHP Code:

global $mycontent 


raztrip 05-22-2008 10:54 AM

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:

Originally Posted by Marco van Herwaarden (Post 1527826)
Add the following line to your plugin:

PHP Code:

global $mycontent 



Marco van Herwaarden 05-22-2008 11:03 AM

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.

raztrip 05-22-2008 11:07 AM

Thank you again, Marco.

- Is the global command a vB function?

- What is the better way to do this, in your experience?

Quote:

Originally Posted by Marco van Herwaarden (Post 1527847)
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.


Marco van Herwaarden 05-22-2008 11:18 AM

"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.

raztrip 05-22-2008 12:22 PM

I've tried this - but it still doesn't work with the postbit template. Why could that be?

Quote:

Originally Posted by Marco van Herwaarden (Post 1527863)
"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.

--------------- Added [DATE]1211547826[/DATE] at [TIME]1211547826[/TIME] ---------------

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
  • Page Generation 0.02260 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
  • (2)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)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