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

Reply
 
Thread Tools Display Modes
  #1  
Old 12-17-2009, 02:11 AM
vaskies vaskies is offline
 
Join Date: Dec 2009
Posts: 34
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default RESOLVED: Calling a Variable from Plugin in VB4

I'm trying to call a variable from a plugin in a stock template. Is it necessary I render the variable in its own custom template first, then call it inside the stock template using {vb:raw $mytemplate}? I thought this seemed superfluous and wanted to be sure as I just finished reading over https://vborg.vbsupport.ru/showthread.php?t=228078 .
Reply With Quote
  #2  
Old 12-17-2009, 02:37 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You may call a varialbe in a stock template, however you much register it for use in that template first. If it's a stock template, then you may have to preregister it if you aren't going to use a template_hook or a variable array that is already registered.
Reply With Quote
  #3  
Old 12-17-2009, 03:53 AM
vaskies vaskies is offline
 
Join Date: Dec 2009
Posts: 34
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I pre-register the variables I'm using in the stock template inside the plugin itself, correct? For instance, I have an array named $array that I'm trying to use in the FORUMHOME template.

In the plugin:
PHP Code:
$var1 "variable one";
$var2 "variable two";
$array = array($var1$var2);
vB_Template::preRegister('FORUMHOME'$array); 
In FORUMHOME template:
PHP Code:
{vb:raw array.var1
Nothing outputs, though.
Reply With Quote
  #4  
Old 12-17-2009, 04:10 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I am pretty sure that $array is a reserved word and you may not use it as a variable name.

And then I think you want to do something more along this line:
PHP Code:
$yourarray = array('var1' => $var1'var2' => $var2); 
Then you may use {vb:raw var1} and {vb:raw var2} in the template.
Reply With Quote
  #5  
Old 12-17-2009, 05:34 AM
consolegaming consolegaming is offline
 
Join Date: Jan 2007
Posts: 168
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

And the plugin needs to be assigned to the parse_templates hook I believe or at least the global hook wouldn't work for me.
Reply With Quote
  #6  
Old 12-17-2009, 05:52 AM
vaskies vaskies is offline
 
Join Date: Dec 2009
Posts: 34
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
I am pretty sure that $array is a reserved word and you may not use it as a variable name.

And then I think you want to do something more along this line:
PHP Code:
$yourarray = array('var1' => $var1'var2' => $var2); 
Then you may use {vb:raw var1} and {vb:raw var2} in the template.
Ah, thank you. I was unaware keys were necessary. I'm new to PHP and never have had the occasion to use a key value pair. Good to know! Also, $array works as a variable. Bad practice though.

Quote:
Originally Posted by consolegaming View Post
And the plugin needs to be assigned to the parse_templates hook I believe or at least the global hook wouldn't work for me.
Hm. I'm using the forumhome_start hook which is working fine for me. I'll keep that in mind though if/when I make a plugin that needs to be used on more than one template. Thanks
Reply With Quote
  #7  
Old 12-17-2009, 02:20 PM
consolegaming consolegaming is offline
 
Join Date: Jan 2007
Posts: 168
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Actually you may be fine with just registering variables but I do know that when I was trying to register a custom template it wouldn't work with the global hook and I read someone's post (I think it was Lynne's) suggesting to someone else to use the parse_templates.

As long as it works for you it doesn't make a difference lol.

EDIT: BTW can someone move my thread from the design froum to this one. Realized after I posted it that it should have been here.
Reply With Quote
  #8  
Old 12-17-2009, 04:01 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by consolegaming View Post
EDIT: BTW can someone move my thread from the design froum to this one. Realized after I posted it that it should have been here.
Hit the Report this Post button and ask to have it moved to the xxx forum.
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 08:53 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.03864 seconds
  • Memory Usage 2,236KB
  • Queries Executed 11 (?)
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
  • (4)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)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