View Full Version : Cant get IF statement to work.
Brexen
08-27-2012, 10:47 AM
Can't get this to work, any ideas on how to fix it?
Code removed :P
I've made a dropdown box for Admins so they can change their userbar outline colour.
Try this:
<vb:if condition="is_member_of($bbuserinfo, 6)">
<vb:if condition="$bbuserinfo['field5'] == 'Grey'"><img src="/images/ranks/grey.png"></vb:if>
<vb:if condition="$bbuserinfo['field5'] == 'Red'"><img src="/images/ranks/red.png"></vb:if>
<vb:if condition="$bbuserinfo['field5'] == 'Blue'"><img src="/images/ranks/blue.png"></vb:if>
<vb:if condition="$bbuserinfo['field5'] == 'Green'"><img src="/images/ranks/green.png"></vb:if>
</vb:if>
Brexen
08-27-2012, 11:22 AM
Try this:
<vb:if condition="is_member_of($bbuserinfo, 6)">
<vb:if condition="$bbuserinfo['field5]> == 'Grey'" <img src="/images/ranks/grey.png"></vb:if>
<vb:if condition="$bbuserinfo['field5]> == 'Red'" <img src="/images/ranks/red.png"></vb:if>
<vb:if condition="$bbuserinfo['field5]> == 'Blue'" <img src="/images/ranks/blue.png"></vb:if>
<vb:if condition="$bbuserinfo['field5]> == 'Green'" <img src="/images/ranks/green.png"></vb:if>
</vb:if>
I did try that, but it gave me an error.
The following error occurred when attempting to evaluate this template:
%1$s
This is likely caused by a malformed conditional statement. It is highly recommended that you fix this error before continuing, but you may continue as-is if you wish.
Is there any way to do this through a Plugin? I'm really new to conditionals and PHP.
Sorry, there were a few other problems. I fixed my post above.
If you'd rather do it in a plugin, you could figure out which file name you want to use and register it to the template. Then you would just need to use a template variable in the img src="", like
Plugin:
$file = '/images/ranks/' . $bbuserinfo['field5'];
vB_Template::preRegister('template_name', array('userbar_color' => $file));
Template:
<vb:if condition="is_member_of($bbuserinfo, 6)">
<img src="{vb:raw userbar_color}">
</vb:if>
But there's really no difference either way.
Brexen
08-27-2012, 12:33 PM
Sorry, there were a few other problems. I fixed my post above.
If you'd rather do it in a plugin, you could figure out which file name you want to use and register it to the template. Then you would just need to use a template variable in the img src="", like
Plugin:
$file = '/images/ranks/' . $bbuserinfo['field5'];
vB_Template::preRegister('template_name', array('userbar_color' => $file));
Template:
<vb:if condition="is_member_of($bbuserinfo, 6)">
<img src="{vb:raw userbar_color}">
</vb:if>
But there's really no difference either way.
After a few edits and combinations of both our codes. Finally got it working. Thanks again.
Scanu
08-27-2012, 12:38 PM
If I'm right he can even do something like this
<vb:if condition="is_member_of($bbuserinfo, 6)">
<img src="/images/ranks/{bbuserinfo.field5}.png">
</vb:if>
But you have to rename pics: green.png became Green.png, blue.png became Blue.png etc..
Yeah, I don't know why I decided to do that in the plugin example but not suggest doing it in the template. I guess I didn't want to deal with the upper/lower case issue, then forgot about it. :confused:
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.