vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Problem with using plugin variables in templates (https://vborg.vbsupport.ru/showthread.php?t=285584)

extends 07-15-2012 04:31 PM

Problem with using plugin variables in templates
 
So for some time now I have been ripping my hair out trying to figure out how to use my plugin variables in my custom templates. After reading countless threads and articles on preReigsting my variables, I have zero luck in actually accomplishing this task.

Here's my basic ripped plugin example hooking newthread_forum_start

Code:

$my_var = "abc";

$templater = vB_Template::create('newtemplate');

$templater->register('my_var', $my_var);
$myrendervar = $templater->render();

vB_Template::preRegister('newthread',array('myrendervar ' => $myrendervar));

trying to access this variable in newthread using {vb:raw myrendervar} does not work. In fact looking at the debug information "newtemplate" is in bolder red letters. I can easily echo my_var, but I cannot use it in newthead template.

What's the deal? What am I not understanding about plugin variables that's preventing me from using basic ones?

Lynne 07-15-2012 05:01 PM

You didn't register $my_var to be used in newthread, you only registered it to be used in newtemplate.

soniceffect 07-15-2012 08:14 PM

Quote:

Originally Posted by extends (Post 2348358)
So for some time now I have been ripping my hair out trying to figure out how to use my plugin variables in my custom templates. After reading countless threads and articles on preReigsting my variables, I have zero luck in actually accomplishing this task.

Here's my basic ripped plugin example hooking newthread_forum_start

Code:

$my_var = "abc";

$templater = vB_Template::create('newtemplate');

$templater->register('my_var', $my_var);
$myrendervar = $templater->render();

vB_Template::preRegister('newthread',array('myrendervar ' => $myrendervar));

trying to access this variable in newthread using {vb:raw myrendervar} does not work. In fact looking at the debug information "newtemplate" is in bolder red letters. I can easily echo my_var, but I cannot use it in newthead template.

What's the deal? What am I not understanding about plugin variables that's preventing me from using basic ones?


You should have a template created named "newtemplate" with {vb:raw my_var} in it. Are you doing this?

extends 07-17-2012 06:24 AM

I got it working thanks to Lynne. I did not know that 'newtemplate' was suppose to target the template I was editing, instead I thought it was some kind of a unique identifier.

But a new problem arises, trying to use my new variable's from the plugin, in a template conditional.

(example)
PHP Code:

$customid 4;
$var2 vB_Template::create('newthread');
$var2->register('checkid'$customid);
$my_var2 $var2->render();
vB_Template::preRegister('newthread',array('checkid' => $my_var2)); 

When I try to use it like so, nothing happens:
(I've used customid as well to cover all my bases)
Code:

<vb:if condition="$foruminfo[forumid] != $checkid">
...
</vb:if>

How can I get this to actually work? it never follows through on the conditional.

soniceffect 07-17-2012 11:15 AM

Have you tried outputting checkid to see what it outputs? This should be your first port of all. Alway output the items you are going to compare to screen to see whether they contain what you expect before you try to compare them.

I believe $foruminfo[forumid] should actually be $forum['forumid']

extends 07-17-2012 07:21 PM

Quote:

Originally Posted by soniceffect (Post 2348914)
Have you tried outputting checkid to see what it outputs? This should be your first port of all. Alway output the items you are going to compare to screen to see whether they contain what you expect before you try to compare them.

I believe $foruminfo[forumid] should actually be $forum['forumid']

$foruminfo[forumid] is the correct variable to use, when trying to find what forum the user has selected.

I tried printing the variable checkid and instead of getting the number 4, I got "Post new thread" and some submit buttons(as if I re-click new topic). Tab confused on this one, as clearly there's some kind of error within the mapping of the variable. But if I echo $customid I do indeed get 4.

Some where in
PHP Code:

$var2->register('checkid'$customid);
$my_var2 $var2->render(); 

is not setting the number correctly.

soniceffect 07-17-2012 07:45 PM

because your actually preregistering the template into itself. You register the variable with newtrhead then you are registering newthread, with newthread

extends 07-18-2012 12:17 AM

oh wow, your absolutely right. I had the idea that you had to go through thous ridiculous loops to per-register your variables.

Got it all working. Thanks.

soniceffect 07-18-2012 08:07 AM

Quote:

Originally Posted by extends (Post 2349110)
oh wow, your absolutely right. I had the idea that you had to go through thous ridiculous loops to per-register your variables.

Got it all working. Thanks.

No prob. Glad its sorted for ya


All times are GMT. The time now is 01:04 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.01789 seconds
  • Memory Usage 1,748KB
  • 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_code_printable
  • (2)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)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