The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Replace Conditionals with Variables?
I've got a ton of conditionals in my postbit, and am wondering if there's a more elegant way to do what I want.
The following swaps backgrounds for usergroups: HTML Code:
<vb:if condition="is_member_of($post, 11)"><div class="userinfoctl"> <vb:else /> <vb:if condition="is_member_of($post, 36)"><div class="userinfogse"> <vb:else /> <vb:if condition="is_member_of($post, 46)"><div class="userinfohtv"> <vb:else /> <vb:if condition="is_member_of($post, 12)"><div class="userinfomta"> <vb:else /> <vb:if condition="is_member_of($post, 47)"><div class="userinfoptc"> <vb:else /> <vb:if condition="is_member_of($post, 14)"><div class="userinfowod"> <vb:else /> <vb:if condition="is_member_of($post, 13)"><div class="userinfo2"> <vb:else /> <vb:if condition="is_member_of($post, 10)"><div class="userinfowtf"> <vb:else /> <div class="userinfo"> </vb:if> </vb:if> </vb:if> </vb:if> </vb:if> </vb:if> </vb:if> </vb:if> HTML Code:
<div class="{vb:raw is_member_of}background">
|
#2
|
||||
|
||||
you wouldnt be able to do it that way, as a user could be a member of more than 1 usergroup. is_member_of is a function which checks through the usergroups a user has assigned and returns true or false. Is it only the primary usergroup that you are interested in?
|
#3
|
|||
|
|||
Right, it was just an example to demonstrate because I wasn't sure if there was a variable I could use.
Yes, I could probably manage with just using the primary usergroup. |
#4
|
||||
|
||||
If thats the case then could probably do a hook which retrieves primary usergroup from the user and makes it available to the css template and use it as you have stated above. If your not sure on how to do this yourself gimme a shout and will throw one together for you. Unless of course primary group is already available, not sure I would have to look.
|
#5
|
||||
|
||||
Create a function, get_member_background($userinfo). Have it return the color you want. Define it in a plugin on global_complete or something.
Do you want to be able to call this function in a template? If so, add another plugin on the template_safe_functions hook, and then add your function name into the allowed functions for conditionals, like so: PHP Code:
HTML Code:
<vb:if condition="$post['background'] = get_member_background($post)"><div class="{vb:raw post.background}"> <vb:else /> <div class="userinfo"> </vb:if> |
#6
|
||||
|
||||
Quote:
|
#7
|
||||
|
||||
Yeah, I was wanting to use array_rand() in one of my own modifications a long time ago, to choose a random image from a set of images to display. Found that handy info in the comments on the manual, else I'd never have known. :3
|
#8
|
||||
|
||||
Apart from other solutions - there is elseif in vB4 conditionals.
<vb:if condition="condition">do smth. if exactly this condition is met. <vb:elseif condition="condition" />do smth. if exactly this condition is met. <vb:elseif condition="condition" />do smth. if exactly this condition is met. <vb:else />do smth. if none of the prior conditions is met. </vb:if> |
#9
|
|||
|
|||
Awesome, thanks all
On a completely unrelated note... I have two mods that are in {vb:raw template_hook.showthread_above_posts}, how would I change the order they're displayed in? Mod A Mod B to Mod B Mod A |
#10
|
||||
|
||||
You can edit the plugin execution order. Most plugins have a default execution order of '5'. Set Mod A to have an execution order of '4'. (That's the simplest way to do it, anyhow.)
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|