Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 01-06-2013, 03:25 PM
grey_goose grey_goose is offline
 
Join Date: Jun 2009
Posts: 284
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Profile Fields & CSS

I'd like to have a profile field that lets users change the color that another field is displayed in. This is what I'm currently using:

PHP Code:
        <vb:if condition="$post['field101'] == 'A'">
            <
font color="green" size="2">
        <
vb:else /><vb:if condition="$post['field101'] == 'B'">
            <
font color="#26466D" size="2">
        <
vb:else /><vb:if condition="$post['field101'] == 'C'">
            <
font color="#2F4F4F" size="2">
        <
vb:else /><vb:if condition="$post['field101'] == 'D'">
            <
font color="royalblue" size="2">
        <
vb:else /><vb:if condition="$post['field101'] == 'E'">
            <
font color="purple" size="2">
        <
vb:else /><vb:if condition="$post['field101'] == 'F'">
            <
font color="#7A7ACC" size="2">
        <
vb:else /><vb:if condition="$post['field101'] == 'G'">
            <
font color="red" size="2">
        <
vb:else /><vb:if condition="$post['field101'] == 'H'">
            <
font color="brown" size="2">
        <
vb:else />
            <
font size="2">
        </
vb:if></vb:if></vb:if></vb:if></vb:if></vb:if></vb:if></vb:if>{vb:raw post.field14}</font
That seems like a ton of conditionals, and it would be more elegant to have multiple CSS classes:

PHP Code:
.Adisplay colorgreen; }
.
Bdisplay color#26466D; } 
..etc...

Then use:
PHP Code:
<span class="{vb:raw bbuserinfo.field101}display">{vb:raw post.field14}</span
However, this doesn't work -- I'm guessing it's because the CSS is rendered before the custom profile fields are read?

Is there a way to do this, or a more elegant way to do what I'm doing?
Reply With Quote
  #2  
Old 01-06-2013, 05:33 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think that should work. You're using $bbuserinfo in the class attribute above - is that what you meant? You used $post in the if/else statements above that. Of course you could use either depending on whether you want the post author's choice to show for everyone or if each user gets to choose what they see.

Where are you putting your CSS? Did you look at the page source to see if the class name is showing up like you'd expect?
Reply With Quote
  #3  
Old 01-06-2013, 07:13 PM
grey_goose grey_goose is offline
 
Join Date: Jun 2009
Posts: 284
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Neither 'post' or 'bbuserinfo' works -- If I look at the source, the class is simply "display" rather than "Adisplay" or "Bdisplay"...
Reply With Quote
  #4  
Old 01-06-2013, 07:34 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

And you're saying that the if/else statements worked? It seems like if that was working, then class="{vb:raw post.field101}display" should work (assuming it's in the same template).
Reply With Quote
  #5  
Old 01-07-2013, 02:04 AM
grey_goose grey_goose is offline
 
Join Date: Jun 2009
Posts: 284
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yep the conditionals work, the classes do not -- which makes me think that the profile fields are being read after the css.
Reply With Quote
  #6  
Old 01-07-2013, 05:21 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Can you post exactly what you have done - what templates you modified and exactly how and any plugin code you've written.
Reply With Quote
  #7  
Old 01-07-2013, 11:13 PM
grey_goose grey_goose is offline
 
Join Date: Jun 2009
Posts: 284
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi Lynne,

The above code is in my postbit_legacy to display a custom user profile field, and a second user profile field selects the display color. Rather than evaluating each color with conditionals, I was wanting to use the profile field to call different css classes -- which seems more efficient than daisy-chaining conditionals in every post.

I haven't done any plugins at all -- just that code in the postbit_legacy.
Reply With Quote
  #8  
Old 01-08-2013, 02:05 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Can we get a screenshot of profile field 101 and 14 in the admincp (with the options) and a link to a thread and can you post 5 lines in the template directly above where you added the code please?

Also, you realize vb4 has elseif? Here's an example from the manual:
Code:
<vb:if condition="$my_variable == 1">
    <p>My variable is equal to one.</p>
<vb:elseif condition="$my_variable == 2" />
    <p>My variable is equal to two.</p>
<vb:else />
    <p>My variable is equal to neither one nor two.</p>
</vb:if>
Reply With Quote
  #9  
Old 01-08-2013, 06:21 PM
grey_goose grey_goose is offline
 
Join Date: Jun 2009
Posts: 284
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm a moron.

This works, I just had a syntax error in my class names :/

I've reduced all those conditionals down to:
Code:
<span class="fontsizesmall {vb:raw post.field101}color">{vb:raw post.field14}</span>
...and it works beautifully. Sorry, and thanks for the willingness to help!

p.s. Thanks for the elseif tip! Didn't know that was new
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:58 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04229 seconds
  • Memory Usage 2,259KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (3)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete