The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
New Templates and registering variables
Hi all,
I could really do with some guidance, I'm struggling to understand the whole process of registering variables in templates. I have managed to get my head round creating new templates and presenting them via plugin within one of the default templates, for example. Plugin. Hook Location - Parse Templates. Title - CVR4_Menu Code - PHP Code:
This works, i created a menu and this is showing - everything is cool here. Now, what i want to achieve (for starters) is present the notifications to this template, i.e. the notifications will be added to the CVR4_Menu Template. I followed several guides - threads i read include.
Plugin. Hook Location - Parse Templates. Title - CVR4_Menu Code - PHP Code:
Plugin. Hook Location - Parse Templates. Title - CVR4_Menu_preregister_notifications Code - PHP Code:
It seems to be that the CVR4_Menu template needs to be registered just like the navbar template before it will accept the notifications variables, but i really don't know where to start. I read in one of the above threads that you can define some variables, like.. PHP Code:
Could someone please help me figure this out, i'm sure it will click for me soon but just now i'm just not getting it. Maybe a working (simple) example of how to get notifications working in a custom template would aid me in my quest to understand. Thanks for reading (all my waffle) |
#2
|
|||
|
|||
The problem is that $notifications_menubits hasn't been set yet when your code runs (hook parse_templates). If you're using 4.1.10, there should be a hook location called process_templates_complete which you could try using instead.
Quote:
The keys can be anything you want as long as they match what you use in the template. The values have to be variables that has a value at the time you call register() or preRegister(). I think a lot of people who are new to vb have problems because it sort of looks like there's a "language" with a set of values you can use wherever you want, but really the hook locations are specific places in the code, so the variables you have available in a plugin differ and depend on the hook location. |
#3
|
||||
|
||||
Quote:
Thank you very much for responding, i'm desperate have this part of VB click for me - I can see many oppertunites and I visualise a much nicer UI for end users, just need to figure it out first Am i looking at two seperate entities? one to register custom variables and another to render templates/conditionals? - if so, i'll overlook the variables for now and focus on the other. Since original post i've moved code around and made another template, so ill use that now to prevent confusion.. Moved code from navbar to custom template called CVR4_searchprofile Quote:
Plugin. Hook Location - process_templates_complete Title - CVR4_searchprofile Code - PHP Code:
PHP Code:
Plugin. Hook Location - process_templates_complete Title - CVR4_searchprofile_notification Code - PHP Code:
What do I need to do to make the notifications appear in my custom template? - i'm bamboozled. |
#4
|
|||
|
|||
Variables you use in a template have to be registered (except some common ones are registered for you), and they have to be registered *before* the template is rendered). preRegister() is used mostly for the existing vb templates because usually there is no hook location to allow you to use register() when the template is being rendered .
So, when you're rendering your own template, call register() before the call to render(), like: PHP Code:
|
#5
|
|||||
|
|||||
Hi, thanks for that.
I tried copy pasting your code in but it didnt work - the notifications drop down isnt showing the number or notification info on the drop down. Im still not sure on how this works, can i break this down they way i see if and determine how close/far of the mark i am? 1. This part grabes the code from the custom template i created. Quote:
Quote:
Quote:
Quote:
Quote:
I've just upgraded to 4.1.11, has something changed to prevent this? - I checked the update notes but couldnt see anything obvious. Thanks --------------- Added [DATE]1330617243[/DATE] at [TIME]1330617243[/TIME] --------------- Thinking abit, is it navbar because thats where the {vb:raw resides? |
#6
|
|||
|
|||
Quote:
Quote:
Actually that last $templater->render() doesn't do anything, I left it there by mistake. Sorry about that. Are you still using hook process_templates_complete ? Just so you know, I haven't tried any of this code myself so I'm not sure why it's not working - maybe that hook won't work either. If I get a chance I'll try it later and see if I can figure out the problem. |
#7
|
||||
|
||||
I'd appreciate that, I'm really not sure why its not working.
Regarding point 4, if I change navbar to say forumhome, then place the <vb:raw CVR4_searchprofile> to forumhome you'd expect that template to render in forumhome? Does duplication of plugins have a negative effect? |
#8
|
||||
|
||||
Hiya, did you get a chance to test this?
|
#9
|
|||
|
|||
No, of course I forgot all about it, sorry. I'll take a look at it now.
|
#10
|
|||
|
|||
OK, this works for me: I have a plugin using hook process_templates_complete with this code (should be same as posted above):
Code:
$templater = vB_Template::create('CVR4_searchprofile'); $templater->register('notifications_menubits', $notifications_menubits); $CVR4_searchprofile = $templater->render(); // but use preRegister() here because you won't have a chance to call // register() for the navbar template vB_Template::preRegister('navbar', array('CVR4_searchprofile' => $CVR4_searchprofile)); Then I created a new CVR4_searchprofile template like this: Code:
<vb:if condition="$show[notifications]"> Show Notifications: {vb:raw notifications_menubits} <vb:else /> Don't Show Notifications </vb:if> and then I put {vb:raw CVR4_searchprofile} in my navbar template. And it looks like this: Attachment 136887 |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|