View Full Version : Use custom var in templates
vsforums
02-01-2013, 02:48 PM
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?
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.
vsforums
02-01-2013, 06:36 PM
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 ?
Somehow i cannot use that code
$supertest = "works";
It must be:
$supertest = 'works';
That's strange - I don't know why that would be.
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.
CoffeeLovesYou
02-10-2013, 01:22 PM
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.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.