Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 02-01-2013, 02:48 PM
vsforums vsforums is offline
 
Join Date: Aug 2006
Posts: 32
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Use custom var in templates

Hi guys,

I tried to do simple thing in vb 3.8

I created a plugin:
Product: vbulletin
hook_location: parse_template
title: test
Plugin PHP Code:
$supertest = "works";

Then i tried to use that $supertest in the navbar template, however that variable doesn't display anything.

Any idea?
Reply With Quote
  #2  
Old 02-01-2013, 06:09 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I don't see anything wrong with that. Are you sure you clicked the 'Yes' radio button to make the plugin active? Are you sure you're looking at a style that corresponds to the template you edited? Try putting something like Supertest: $supertest in the template and see if you at least see the Supertest: part.
Reply With Quote
  #3  
Old 02-01-2013, 06:36 PM
vsforums vsforums is offline
 
Join Date: Aug 2006
Posts: 32
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Somehow i cannot use that code
$supertest = "works";
It must be:
$supertest = 'works';

So i can know use $supertest but what about php global?

If i have a global MY_GLOBAL how i can use it later in the template? If i put MY_GLOBAL then it displays "MY_GLOBAL" instead of value ?
Reply With Quote
  #4  
Old 02-01-2013, 08:12 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by vsforums View Post
Somehow i cannot use that code
$supertest = "works";
It must be:
$supertest = 'works';
That's strange - I don't know why that would be.


Quote:
So i can know use $supertest but what about php global?

If i have a global MY_GLOBAL how i can use it later in the template? If i put MY_GLOBAL then it displays "MY_GLOBAL" instead of value ?
Even global variables need a $ in front. And as far as I know, every variable you use in php is a global if you use it outside of any function, or if you declare it with a global statement. There are some special variables that are global everywhere, like $_GET[], $_POST[], etc. Maybe that's what you're thinking of.

But I looked at the code and the parse_templates hook and the place where the navbar template is evaled are both outside any function, so you should be able to use any variable name you want.
Reply With Quote
  #5  
Old 02-10-2013, 01:22 PM
CoffeeLovesYou CoffeeLovesYou is offline
 
Join Date: Feb 2010
Posts: 176
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by vsforums View Post
Somehow i cannot use that code
$supertest = "works";
It must be:
$supertest = 'works';
I went through the same thing on my forum when making my own mod that were hooked to global start. The reason is, the double quotations clash with code that is in global.php. For example, if your mysql query is..

$sql='SELECT * from user WHERE userid='50''

what will happen is, the php script will only register:


$sql='SELECT * from user WHERE userid='
as the start and end of the SQL query. the 50'' part will cut off.
So to work around, you need to do something like;

$sql="SELECT * from user WHERE userid='50'"

same thing with plugins hooked to global_start (not sure if it affects over hooks)

instead of

echo "Hello!";
you need
echo 'Hello!';

sounds like i'm teaching you basic stuff lol but for some reason this is what I have noticed.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:11 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.08752 seconds
  • Memory Usage 2,198KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete