![]() |
Display custom field in memberlist that contains multiple selections.
Yep, it's me again. ;)
I have been using the code below to display custom fields in my new custom memberlist. It's been working great so far, but I just realized it doesn't work like I intended when the custom field values are from a multiple selection check box. Code:
{vb:raw userinfo.field17} Example: User can select any number of the following - Snacks, Breakfast, Lunch, Dinner So if they check Breakfast and Dinner, that is what I want the output to be in my template. Instead, the code above will output the number assocciated with that option. Thanks! :D |
Custom Fields with more than one option are sorted based on the geometric formula. Meaning You would do something like this:
Userfield6(Radio, Select, Checkbox it doesn't matter) Yes(1) No(2) Maybe(4) Never(8) PHP Code:
so to continue it would be 1,2,4,8,16,32,64 etc.. |
I checked the values in the databse to make sure I had them correct, but this doesn't seem to work. My template is still outputting numbers instead of text values.
PHP Code:
Code:
{vb:raw userinfo.field23} |
I didn't convert it to template format
Something like this: <vb:if condition="$userfield['field23'] & 1"> Yes <vb:elseif condition="userfield['field23'] & 2"> No <vb:endif> |
I am using this in my template and am getting an error when I try to save the template. Can anyone see a problem with this?
Code:
<vb:if condition="$userfield['field23'] & 1"> 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. |
All your condition expressions except the first one are missing the $ in front of "userfield".
|
I can't believe I didn't see that!! Lol!
However, I was finally able to save the template changes, but that code is not outputting anything. Grrr! This is what I have... Code:
<vb:if condition="$userfield['field23'] & 1"> |
It might help to temporarily output the value of $userfield['field23'] to see what's going on.
That seems like a strange set of bits to check (normally they'd be 1, 2, 4, 8, 16, 32, 64, etc), but I don't know exactly how they're being used so what you have could be correct. |
I got those numbers from the database. They may have skipped around from me deleting and adding options. How can I temporarily output the values?
|
Quote:
Quote:
|
Okay, you were right about the numbers. Some were wrong. I updated the numbers though and it still didn't do anything. I tried using == like you said and that didn't work. Did I do it like you were thinking... ?
Code:
<vb:if condition="$userfield['field23'] == 1"> |
OK, I went back and read the above posts again, and since it's multiple selection, I think you do want to use '&'. And are you sure $userfield is what you want to check? You might want $bbuserinfo[field23] (assuming this is displaying the data to the user who selected it, and not to another user (like an admin or someone).
Also, like you mentioned in an earlier post, since it's possible to have multiple options selected you don't want to use elseif, you would just want a bunch of if statements, like: Code:
<vb:if condition="$bbuserinfo['field23'] & 1">Unknown </vb:if> |
This output will be shown to any usergroup type viewing it on a public profile and also in the custom member list I created. It is not meant to show the viewer their own personal selections, but to show the viewer the selection of whoever's profile they are viewing.
|
In that case you don't want to use $bbuserinfo, of course.
|
So this does not work either. Any ideas?
Code:
<vb:if condition="$userfield['field23'] & 1"> |
Should have asked this from the start, but which template are you putting that in?
|
It is going in the template memberinfo_block_aboutme
|
Then I think you want this:
Code:
<vb:if condition="$userinfo['field23'] & 1">Unknown </vb:if> |
When I try to save the template with that, I get an error that says "adding child to non-existent node!".
Code:
<vb:if condition="$userinfo['field23'] & 1"> |
I think you need to take the '/'s out of the <vb:if... tags, like this:
Code:
<vb:if condition="$userinfo['field23'] & 1"> |
I had just now figured that out and came back to tell you. Lol! BUT... IT ALL WORKS NOW!! Yeay!!!!
Thanks sooooo much for your help!! I really appreciate it! :D For anyone that wants to know, the final working code to display a custom user profile field variable (multiple selection checkbox values) in a template is: Code:
<vb:if condition="$userinfo['field23'] & 1"> |
Edit: Nevermind I just saw your post after refreshing :cool:.
What template are you including this in? *You can view the current usergroups in the Usergroup Manager, hover over the usefield link to see a URL displayed in your browser and note the id# ;). |
I don't know much but shouldn't it be something like this:
HTML Code:
<vb:if condition="$vbulletin->userinfo['field23'] == '1'"> |
Quote:
|
What I posted last does work. I am going to attempt to put this together as a mod. I will reference it here when I am done. Wish me luck! I've never posted a mod before!
@KH99 and @OcR Envy, I will include you for helping me! :) |
All times are GMT. The time now is 05:50 PM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|