vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Call Vars from vBulletin into Plugin and echo them in a template (https://vborg.vbsupport.ru/showthread.php?t=278843)

skateme 02-19-2012 08:41 PM

Call Vars from vBulletin into Plugin and echo them in a template
 
I want to apply the "substr()" function to one of the custom profile fields. I will display the modified field in my postbit. I am trying to display the last two characters of the college graduation year in the postbit as follows: College 'YR.

I know I have to create a plugin calling in the field4 (college graduation year) variable, apply the substr() function, and create a new variable to echo in my template.

My plugin is as follows:
Code:

$vbulletin->profilefieldname[field4] = $collgrad;
$collgradtruncated = substr($collgrad, 2);


$mytemplater = vB_Template::create('mytemplate');
$mytemplater->register('my_str', $my_str);
$myrendervar = $mytemplater->render();
vB_Template::preRegister('postbit_legacy',array('myrendervar ' => $myrendervar));

This is the relevant code in the postbit_legacy:
Code:

<vb:if condition="$post['field4']"><dt>{vb:rawphrase college}</dt> <dd>{vb:raw post.field4} '{vb:raw collgradtruncated}</dd></vb:if>
Obviously, it does not work. I was hoping someone could tell me the following:
1) how to call profile field values in my plugin
2) setup a variable in my plugin that I can use in my template
3) tell me what is wrong with my code
4) fix the code for me

Thank you so much!

kh99 02-19-2012 08:58 PM

I think what you want for the first line is:

Code:

$collgrad = $post['field4'];
and you have an extra space in 'myrendervar ' lower down.

But I think maybe you just want to do this:
Code:

$collgradtruncated = substr($post['field4'], -2);
vB_Template::preRegister('postbit_legacy',array('collgradtruncated' => $collgradtruncated));


then in the template you can use {vb:raw collgradtruncated} for the two digit year.

You didn't say which hook location you're using.

skateme 02-19-2012 09:36 PM

Thanks Kevin. I'm using global_start.

The code you supplied doesn't function. Do I need to add something else?

kh99 02-19-2012 09:46 PM

If I understand what you're doing, you want to put the college year info in the postbit, so you want it to be the post author's year? Then you need to use a hook location that is called once per post, before it's rendered, like postbit_display_complete.

skateme 02-19-2012 09:57 PM

Awesome! That worked great! Thanks so much for the help!


All times are GMT. The time now is 12:52 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.01568 seconds
  • Memory Usage 1,715KB
  • 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
  • (4)bbcode_code_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