vb.org Archive

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

evenmonkeys 07-07-2012 02:30 AM

Running Quick PHP in a Template Via Plugin
 
I'm trying to just make a very simple and quick variable that I'd like to place into a template. I made a plugin using global_start and just put something along the lines of:
Code:

$variable = 1;
Then I try to pull that variable in a template, but it doesn't work.

Am I missing something?

Simon Lloyd 07-07-2012 03:06 AM

You're correct you simply put $variable wherever you want to see the number 1 :)

evenmonkeys 07-07-2012 03:41 AM

It doesn't work, unfortunately.

My plugin literally is under global_start:
Code:

$variable = 1;
Within my template is
HTML Code:

Variable = $variable.
Doesn't work.

Simon Lloyd 07-07-2012 04:35 AM

Nope, in your template just put $variable
or you can use it like this <td>$variable2345</td> which will give you 12345

evenmonkeys 07-07-2012 01:18 PM

Right. But it doesn't work. I put $variable and it shows nothing. I pull up the source and it's like it's not even there.

kh99 07-07-2012 01:22 PM

Where are you using your template? Some templates are used inside a function, and then you can't use global variables directly. You could try using $GLOBALS['variable'].

evenmonkeys 07-07-2012 01:36 PM

I guess that makes sense.

I'm modifying 4 templates:

forumhome_forumbit_level1_nopost
forumhome_forumbit_level1_post
forumhome_forumbit_level2_nopost
forumhome_forumbit_level2_post

Simon Lloyd 07-07-2012 01:41 PM

I guess it would be best if you showed us EXACTLY what you are using, with what hook and where you are trying to use it in those templates.

kh99 07-07-2012 01:44 PM

Quote:

Originally Posted by evenmonkeys (Post 2345804)
I guess that makes sense.

I'm modifying 4 templates:

forumhome_forumbit_level1_nopost
forumhome_forumbit_level1_post
forumhome_forumbit_level2_nopost
forumhome_forumbit_level2_post


I think that's your problem - those are used in the function construct_forum_bit() (in includes/functions_forumlist.php), so your global variable isn't in scope.

evenmonkeys 07-08-2012 07:42 PM

Awesome. Thank you. I see what I'm not doing correctly. I just had to change the hook location. Appreciate the help, kh99.


All times are GMT. The time now is 09:23 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.01721 seconds
  • Memory Usage 1,727KB
  • 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_code_printable
  • (1)bbcode_html_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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