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

Discussion in 'XenForo Development Discussions' started by DieselMinded, May 27, 2016.

  1. DieselMinded

    DieselMinded Active Member

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

    rainmotorsports Well-Known Member

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

    DieselMinded Active Member

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

    rainmotorsports Well-Known Member

    Technically yeah actually that could work lol. Good thinking.
     
    DieselMinded likes this.
  5. DieselMinded

    DieselMinded Active Member

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

    DieselMinded Active Member

    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>
    :(
     
  7. Xon

    Xon Well-Known Member

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

    DieselMinded Active Member

    thanks for your help @Xon i still cannot get the images to show
     
  9. Xon

    Xon Well-Known Member

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

    DieselMinded Active Member

    shows a broken image (http://www.mymilitia.com/vault/icons/.png)

    btw here is my fields

    44444.png
     
  11. DieselMinded

    DieselMinded Active Member

  12. Xon

    Xon Well-Known Member

    Can you try:
    Code:
    {xen:helper dump, $user.customFields}
    
    or
    Code:
    {xen:helper dump, $visitor.customFields}
    
    I can't offer much else support sorry.
     
    DieselMinded likes this.
  13. DieselMinded

    DieselMinded Active Member

    Thanks for your help @Xon , not sure where to put your helper code
     
  14. RichardKYA

    RichardKYA Well-Known Member

    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?
     
  15. DieselMinded

    DieselMinded Active Member

    Thanks , just gave it a shot , didn't work either
     
  16. RichardKYA

    RichardKYA Well-Known Member

    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"
     
  17. DieselMinded

    DieselMinded Active Member

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

    DieselMinded Active Member

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

    DieselMinded Active Member

    that makes the image be there all the time , it don't matter if i have ARMY checked or not
     
  20. DieselMinded

    DieselMinded Active Member

    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>
     

Share This Page