vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   Cant get IF statement to work. (https://vborg.vbsupport.ru/showthread.php?t=287156)

Brexen 08-27-2012 10:47 AM

Cant get IF statement to work.
 
Can't get this to work, any ideas on how to fix it?

Code:

Code removed :P
I've made a dropdown box for Admins so they can change their userbar outline colour.

kh99 08-27-2012 11:20 AM

Try this:

Code:

<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

Quote:

Originally Posted by kh99 (Post 2360395)
Try this:

Code:

<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.

Code:

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.

kh99 08-27-2012 11:38 AM

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:
Code:

$file = '/images/ranks/' . $bbuserinfo['field5'];
vB_Template::preRegister('template_name', array('userbar_color' => $file));


Template:
Code:

<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

Quote:

Originally Posted by kh99 (Post 2360413)
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:
Code:

$file = '/images/ranks/' . $bbuserinfo['field5'];
vB_Template::preRegister('template_name', array('userbar_color' => $file));


Template:
Code:

<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
Code:

<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..

kh99 08-27-2012 01:11 PM

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:


All times are GMT. The time now is 02:03 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01345 seconds
  • Memory Usage 1,729KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (9)bbcode_code_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete