View Full Version : Problem with using plugin variables in templates
extends
07-15-2012, 04:31 PM
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
$my_var = "abc";
$templater = vB_Template::create('newtemplate');
$templater->register('my_var', $my_var);
$myrendervar = $templater->render();
vB_Template::preRegister('newthread',array('myrend ervar ' => $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
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
$my_var = "abc";
$templater = vB_Template::create('newtemplate');
$templater->register('my_var', $my_var);
$myrendervar = $templater->render();
vB_Template::preRegister('newthread',array('myrend ervar ' => $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)
$customid = 4;
$var2 = vB_Template::create('newthread');
$var2->register('checkid', $customid);
$my_var2 = $var2->render();
vB_Template::preRegister('newthread',array('checki d' => $my_var2));
When I try to use it like so, nothing happens:
(I've used customid as well to cover all my bases)
<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
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
$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
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
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.