Register Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools
  #1  
Old 07 Jul 2013, 13:32
Seductor Seductor is offline
 
Join Date: May 2011
Understanding how to preregister variables.

Hi there,

I'm trying to understand how to preregister varaibles. In this example, I'm using FORUMHOME. This is my plugin:


And this is my template:


Nothing is being displayed. Why?

Another question. I have read this tutorial, indeed:
http://www.vbulletin.org/forum/showthread.php?t=228078

But I don't understand wht I need to use vB_Template::create to register a variable in a existing template. Does vB_Template::create create a new template and will I find it in my templates list? Is there any way to register a variable without creating and rendering a template?

Thanks.
Reply With Quote
  #2  
Old 07 Jul 2013, 15:12
kh99 kh99 is offline
 
Join Date: Aug 2009
Real name: Kevin
There are two ways to register variables: you can either register them after the template is created but before render() is called (as is done with my_str and my_arr in your example), or you can use preRegister(), which has to be done before the template is rendered. I think the reason for preRegister is mostly because without it, there would need to be a hook location everywhere a template is rendered, or else you couldn't add variables to the existing vb templates.

So the reason your code doesn't work is because you have the call to preRegister() after the template is rendered. But since you are creating and rendering your own custom template, you should just use a call to register.

BTW, I should have explained this better when answering in your other thread, so sorry about that.
Reply With Quote
  #3  
Old 07 Jul 2013, 16:44
Seductor Seductor is offline
 
Join Date: May 2011
kh99, could you givfe me an example about the second way, please?

I have a question about my example. I don't want to render my own template, I want to use the FORUMHOME template. So, could I skip and omit the vBTemplate::create and the render function?

If so, I understood that I only would need to call preRegister(), would it be enough?

For example,

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

And then could I access it from FORUMHOME using {vb:raw my_attr}?
Reply With Quote
  #4  
Old 07 Jul 2013, 17:29
kh99 kh99 is offline
 
Join Date: Aug 2009
Real name: Kevin
Originally Posted by Seductor View Post
If so, I understood that I only would need to call preRegister(), would it be enough?

For example,

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

And then could I access it from FORUMHOME using {vb:raw my_attr}?
Almost. First, the preRegister line should be like this:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


(it has a comma instead of =>). Then in your template you'd use {vb:raw red} and {vb:raw yellow}. It *is* possible to register an array then use loop tags in the template, but I'm going to assume that's not what you're trying to do, unless you say differently.

Is that the example you wanted? If you're not rendering your own template then you don't need to (and in fact you can't) use register().
Reply With Quote
  #5  
Old 07 Jul 2013, 18:05
Seductor Seductor is offline
 
Join Date: May 2011
Originally Posted by kh99 View Post
It *is* possible to register an array then use loop tags in the template, but I'm going to assume that's not what you're trying to do.
I don't want to do it, but in that case, could I do...?


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

--------------- Added 07 Jul 2013 at 18:42 ---------------

Okay. there must be something wrong. I have edited {vb:raw header}and added somwhere:
{vb:raw yellow}a

Notice that there is a letter a.

I have hooked the plugin to global_start, then I turned on the debug mode and I checked that global_start is executed.

My plugin code is:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Why is not showing anything? It is showing only the letter a, as If {vb:raw yellow} is void.

What am I doing wrong?

Last edited by Seductor; 07 Jul 2013 at 18:43.
Reply With Quote
  #6  
Old 07 Jul 2013, 19:19
kh99 kh99 is offline
 
Join Date: Aug 2009
Real name: Kevin
The vb:each looks ok. But I.m not sure because I have to look it up every time. Of course if you wanted to do that you'd have to register the array as my_attr, which is a bit different than registering separate vars.

If you want to add something to header, headinclude, or footer (and a couple others I can't remember), you need a plugin using hook parse_templates. The hook code is called from inside a function, so you need to use a "global" statement for any globals you need.
Reply With Quote
  #7  
Old 07 Jul 2013, 19:49
Seductor Seductor is offline
 
Join Date: May 2011
There were not luck for the plugin. Despite it is hooked to parse_templates, it still does not show anything... this is crazy, uh?

--------------- Added 07 Jul 2013 at 20:05 ---------------

Originally Posted by kh99 View Post
Then in your template you'd use {vb:raw red} and {vb:raw yellow}. ).
Finally I discovered why. It is not {vb:raw red}, but {cv:raw apple}. It is 'key' => 'value'.

It works now!
Reply With Quote
  #8  
Old 07 Jul 2013, 20:10
kh99 kh99 is offline
 
Join Date: Aug 2009
Real name: Kevin
Oops, that was careless of me. Glad you figured it out.
Reply With Quote
  #9  
Old 07 Jul 2013, 22:58
tbworld tbworld is offline
 
Join Date: Oct 2008
Originally Posted by kh99 View Post
Oops, that was careless of me. Glad you figured it out.
lol, I would have made the same mistake. When you write this stuff quickly to reply to a message and not look up the syntax for vbulletin .. well lets say I always get it slightly wrong.

Last edited by tbworld; 07 Jul 2013 at 23:04.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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


New To Site? Need Help?

All times are GMT. The time now is 07:54.

Layout Options | Width: Wide Color: