• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Can someone give me a hand for a sec... Custom UserFields

DieselMinded

Well-known member
#1
I have a custom user fields..

a.png

I show them on message.userinfo...

b.png

My Current Code looks like this...

Code:
<xen:if is="{$user.customFields.nra}">
<a href="https://membership.nrahq.org/forms/signup.asp?campaignid=XR030536" target="_new"><img src="vault/icons/nra9.png" height="36px" width="36px" title="CLICK TO JOIN NRA" alt="CLICK TO JOIN THE NRA NOW"></a>
</xen:if>
    <xen:if is="{$user.customFields.ccw}">
<a><img src="vault/icons/ccw.png" height="36px" width="36px" title="Concealed Carry Holder"></a>
</xen:if>
    <xen:if is="{$user.customFields.3per}">
<a><img src="vault/icons/3per.png" height="36px" width="36px" title="Three Percenter"></a>
</xen:if>
    <xen:if is="{$user.customFields.Oath}">
<a><img src="vault/icons/ok8.png" height="36px" width="36px" title="Oath Keeper"></a>
</xen:if>
    <xen:if is="{$user.customFields.fb}">
<a href="{$user.customFields.fb}" target="_new"><img src="vault/icons/fb8.png" height="36px" width="36px" title="Facebook" alt="Facebook"></a>
</xen:if>
<xen:if is="{$user.customFields.youtube}">
<a href="{$user.customFields.youtube}" target="_new"><img src="vault/icons/yt8.png" height="36px" width="36px" title="Youtube" alt="Youtube"></a>
</xen:if>
<xen:if is="{$user.ld_links_count}"><a href="{xen:link 'linkdirectory/user', $user}"><img src="vault/icons/link1.png" height="36px" width="36px" title="Links" alt="Links"></a></xen:if>
I do not know how to code this for multiple choice SOMETHING LIKE THIS ......

Code:
<xen:if is="{$user.customFields.service}">
IF OPTION 1 SELECTED SHOW
<a><img src="vault/icons/army.png" height="36px" width="36px" title="ARMY" alt="ARMY"></a>
IF OPTION 2 SELECTED SHOW
<a><img src="vault/icons/navy.png" height="36px" width="36px" title="NAVY" alt="NAVY"></a>
IF OPTION 3 SELECTED SHOW
<a><img src="vault/icons/usmc.png" height="36px" width="36px" title="USMC" alt="USMC"></a>
IF OPTION 4 SELECTED SHOW
<a><img src="vault/icons/usaf.png" height="36px" width="36px" title="USAF" alt="USAF"></a>
IF OPTION 5 SELECTED SHOW
<a><img src="vault/icons/coast.png" height="36px" width="36px" title="Coast Guard" alt="Coast Guard"></a>
</xen:if>
TIA for any help
 

rainmotorsports

Well-known member
#2
Xenforo does not support and as of last suggestion has not intended to add switch or case statements that make this clean and easy. Honestly most things that complicated will be done in PHP then passed to the template.

But sometimes you just have to write a big nasty if else statement. Checking the text or numerical value of the variable and then stepping through each if until a result is displayed.

Unless I'm wrong about a switch like statement being available.
 

DieselMinded

Well-known member
#3
I'm dangerously close i think..

Code:
<xen:if is="{$user.customFields.service}">
<a><img src="vault/icons/{$choice}.png" height="36px" width="36px" title="{$choice}" alt="{$choice}"></a>
</xen:if>
 

DieselMinded

Well-known member
#5
Technically yeah actually that could work lol. Good thinking.
This is its not pulling the images correctly and it don't support selecting more than one option either so i need someone to help me figure this out or ill have to do them all one by one

it puts this in postbit

Code:
http://www.mymilitia.com/vault/icons/.png
 

DieselMinded

Well-known member
#6
Code:
<xen:if is="{$user.customFields.service}">
<is option 1>
<a><img src="vault/icons/army.png" height="36px" width="36px" title="ARMY" alt="ARMY"></a>
<else>
<a><img src="vault/icons/navy.png" height="36px" width="36px" title="NAVY" alt="NAVY"></a>
<else>
<a><img src="vault/icons/usmc.png" height="36px" width="36px" title="USMC" alt="USMC"></a>
<else>
<a><img src="vault/icons/usaf.png" height="36px" width="36px" title="USAF" alt="USAF"></a>
<else>
<a><img src="vault/icons/coast.png" height="36px" width="36px" title="Coast Guard" alt="Coast Guard"></a>
</xen:if>
:(
 

Xon

Well-known member
#7
Something like the following will work:
Code:
<xen:if is="{$user.customFields.service} == 'army' ">
<a><img src="vault/icons/army.png" height="36px" width="36px" title="ARMY" alt="ARMY"></a>
<xen:elseif is="{$user.customFields.service} == 'navy' "/>
<a><img src="vault/icons/navy.png" height="36px" width="36px" title="NAVY" alt="NAVY"></a>
<xen:elseif is="{$user.customFields.service} == 'usmc' "/>
<a><img src="vault/icons/usmc.png" height="36px" width="36px" title="USMC" alt="USMC"></a>
<xen:elseif is="{$user.customFields.service} == 'usaf' "/>
<a><img src="vault/icons/usaf.png" height="36px" width="36px" title="USAF" alt="USAF"></a>
<xen:elseif is="{$user.customFields.service} == 'coastguard' "/>
<a><img src="vault/icons/coast.png" height="36px" width="36px" title="Coast Guard" alt="Coast Guard"></a>
</xen:if>
Adjust the right-hand side value (ie 'army') for each ifstatement as required.
 

Xon

Well-known member
#9
thanks for your help @Xon i still cannot get the images to show
try:
Code:
<xen:if is="{$user.customFields.service}">
<a><img src="vault/icons/{$user.customFields.service}.png" height="36px" width="36px" title="{$user.customFields.service}" alt="{$user.customFields.service}"></a>
</xen:if>
 

RichardKYA

Well-known member
#14
Have you tried...

Code:
<a><img src="vault/icons/army.png" height="36px" width="36px" title="{$user.customFields.service.army}" alt="{$user.customFields.service.army}"></a>

....just to make sure the file path is correct and that your customfields are working?
 

DieselMinded

Well-known member
#15
Have you tried...

Code:
<a><img src="vault/icons/army.png" height="36px" width="36px" title="{$user.customFields.service.army}" alt="{$user.customFields.service.army}"></a>

....just to make sure the file path is correct and that your customfields are working?
Thanks , just gave it a shot , didn't work either
 

RichardKYA

Well-known member
#16
What does it show in your browser inspector? Does the img tag have the correct title and alt? eg: title="army" alt="army" ?

And if the image is not loading, then the path must be incorrect, assuming your "vault" folder is in the root, try: "/vault/icons/army.png"
 

DieselMinded

Well-known member
#17
Code:
<xen:if is="{$user.customFields.service}">
<a><img src="vault/icons/army.png" height="36px" width="36px" title="ARMY" alt="ARMY"></a>
<a><img src="vault/icons/navy.png" height="36px" width="36px" title="NAVY" alt="NAVY"></a>
<a><img src="vault/icons/usmc.png" height="36px" width="36px" title="USMC" alt="USMC"></a>
<a><img src="vault/icons/usaf.png" height="36px" width="36px" title="USAF" alt="USAF"></a>
<a><img src="vault/icons/coast.png" height="36px" width="36px" title="Coast Guard" alt="Coast Guard"></a>
</xen:if>
SHOWS...

22222.png
 

DieselMinded

Well-known member
#18
What does it show in your browser inspector? Does the img tag have the correct title and alt? eg: title="army" alt="army" ?

And if the image is not loading, then the path must be incorrect, assuming your "vault" folder is in the root, try: "/vault/icons/army.png"
i have to retest your code above , i couldn't get the images to show again it was because i had all 5 options checked
 

DieselMinded

Well-known member
#19
Have you tried...

Code:
<a><img src="vault/icons/army.png" height="36px" width="36px" title="{$user.customFields.service.army}" alt="{$user.customFields.service.army}"></a>

....just to make sure the file path is correct and that your customfields are working?
that makes the image be there all the time , it don't matter if i have ARMY checked or not
 

DieselMinded

Well-known member
#20
Opps i for got the if statement , your code works for ARMY now how to include the other options?

Code:
<xen:if is="{$user.customFields.service}"><a><img src="vault/icons/army.png" height="36px" width="36px" title="{$user.customFields.service.army}" alt="{$user.customFields.service.army}"></a></xen:if>