vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Use custom var in templates (https://vborg.vbsupport.ru/showthread.php?t=294658)

vsforums 02-01-2013 02:48 PM

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?

kh99 02-01-2013 06:09 PM

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 ?

kh99 02-01-2013 08:12 PM

Quote:

Originally Posted by vsforums (Post 2401140)
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.

CoffeeLovesYou 02-10-2013 01:22 PM

Quote:

Originally Posted by vsforums (Post 2401140)
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.


All times are GMT. The time now is 11:39 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.01135 seconds
  • Memory Usage 1,724KB
  • 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
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)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