The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
Template Variable Hook
Hey all. I read this article: https://vborg.vbsupport.ru/showthread.php?t=228078 (You know, searching before posting) and I was still a bit confused. I want to do the following:
For each post, I want to set a variable to use in the postbit based on the user's usergroup. I imagine I can use the last part of the article to pass the variable to the postbit_legacy template(?) but I don't know where I should place my hook or how to get the poster's info from that hook. Help appreciated! |
#2
|
|||
|
|||
If you want to add something to the postbit template, postbit_display_complete is probably a good hook to use. The template name you can use to preRegister is $this->template_prefix . $this->templatename.
I think the post author's usergroup info might already be in the $post array, so you might not need a plugin if you can do what you want to do using is_member_of() in a template conditional. |
#3
|
||||
|
||||
I'd prefer to use a hook because I will be doing multiple checks and there are multiple outcomes. I don't want to lengthen the template, so I'd rather just do all that in php and pass off the results.
|
#4
|
||||
|
||||
So after thinking awhile, I think this would be better to store in the $userdata array, but I don't want it to be premanent (drawn from the database) but rather dynamically generated when the userdata is retrieved. I think this will be easier than to do a check on every postbit, considering you may have the same poster multiple times. Is there a way to do that?
|
#5
|
|||
|
|||
I think you can use the hook fetch_userinfo and look at the user info in $user, and add whatever you want to it. Then it should appear in $post in the postbit. (And it's cached for you).
|
#6
|
||||
|
||||
So I could essentially just add $user['blabla'] = xxx; to set that within the userinfo? After that wouldn't I still need a template hook to pass those variables, or does userdata work by allowing anything in that data set to be referenced?
|
#7
|
|||
|
|||
I'm not sure if I follow that, but when the postbit tremplate is being rendered, the userinfo is combined with the post info and registered to the template as 'post', so you should be able to use {vb:raw post.blabla} in the postbit (or postbit_legacy) template without doing anything else.
|
#8
|
||||
|
||||
So it doesn't seem to be working. Here is what I have at the hook "fetch_userinfo".
PHP Code:
|
#9
|
|||
|
|||
Well, using hook fetch_userinfo you'd want to use $user instead of $userinfo. You could try that, since it should be pretty quick to make that change, but looking at showthread.php I think I may have been wrong. Sorry about that, but it looks like showthread.php gets the userinfo as part of the query for posts in a thread, so I guess it doesn't call fetch_userinfo(). So it doesn't look like you can do much better than doing it in postbit_complete and using $post in place of $userinfo (although you should otherwise be able to use the same code, of course). And if you want to cache it, you'll have to build your own (just save arrays with lrank and srank in a global array with userid as index, and check that before executing your code). But you're not doing a db query or anything to get your answer, so if it were me I probably wouldn't bother.
|
#10
|
||||
|
||||
Yea, after I thought about it I realized even if it did call fetch_userinfo, it would still be calling that on each individual post so I wouldn't really be saving any time code-wise. I just switched it to $post and moved to the postbit_display_complete hook and it works like a charm. Now just a bit more and it'll be doing what I want.
|
Благодарность от: | ||
kh99 |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|