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

Link depends on option

Discussion in 'XenForo Development Discussions' started by Matthew Hawley, Jun 25, 2013.

  1. Matthew Hawley

    Matthew Hawley Well-Known Member

    So...if want a link to change depending on an option how would I do this?

    Option = not checked
    --- Default link

    Option = checked
    --- Link changes

    Thanks!
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    You've not really given enough information, so I'll assume you mean this:

    Code:
    <xen:if is="{$xenOptions.yourOptionId} == 'some_value'">
        <a href="{xen:link link/default}">Default Link</a>
    <xen:else />
         <a href="{xen:link link/changed}">Different link</a>
    </xen:if>
     
    SneakyDave and Matthew Hawley like this.
  3. Matthew Hawley

    Matthew Hawley Well-Known Member

    Thanks! What would 'some value' mean? checked?
     
  4. Chris D

    Chris D XenForo Developer Staff Member

    It depends on the option type.

    If it's just an on/off checkbox you can do this:

    Code:
    <xen:if is="{$xenOptions.yourOptionId}">
        <a href="{xen:link link/default}">Default Link</a>
    <xen:else />
         <a href="{xen:link link/changed}">Different link</a>
    </xen:if>
    Because an on/off checkbox is either true or false then you don't need to specify the value.

    Some options (e.g. radio buttons) have different values some "some_value" could be the ID of the option value.
     
    Matthew Hawley likes this.
  5. Matthew Hawley

    Matthew Hawley Well-Known Member

    It worked. Thank you! :)
     
  6. Matthew Hawley

    Matthew Hawley Well-Known Member

  7. James

    James Well-Known Member

    Add another <xen:else />

    <xen:if is="">

    <xen:elseif is="" />

    <xen:else />

    </xen:if>
     
  8. Matthew Hawley

    Matthew Hawley Well-Known Member

    Thanks!
     
  9. Matthew Hawley

    Matthew Hawley Well-Known Member

    It didn't work. This is the code.

    Code:
    <xen:if is="{$xenOptions.enableNotableMembers}">
      <a href="{$tabs.members.href}" class="navLink">{$tabs.members.title}</a>
    <xen:else />
      <a href="{xen:link members/list}" class="navLink">{$tabs.members.title}</a>
    <xen:else />
    <xen:if is="{$xenOptions.enableMemberList}">
    <xen:elseif is="{$xenOptions.enableNotableMembers}" />
    <a href="{xen:link recent-activity}" class="navLink">{$tabs.members.title}</a>
    </xen:else>
    </xen:if>
    Also when I disable Notable members the link still shows, when i add your code.
     
  10. Chris D

    Chris D XenForo Developer Staff Member

    You can't have multiple else statements like that and you can't combine an additional if statement like you have.
     
  11. Matthew Hawley

    Matthew Hawley Well-Known Member

    Then what do I do?
     
  12. SneakyDave

    SneakyDave Well-Known Member

    Try this:

    If NotableMembers is enabled provide that link,
    otherwise, if MembersList enabled, provide that link.
    otherwise, do some other link.

    I think this might work.
    Code:
    <xen:if is="{$xenOptions.enableNotableMembers}">
      <a href="{$tabs.members.href}" class="navLink">{$tabs.members.title}</a>
    <xen:elseif "{$xenOptions.enableMemberList}" />
      <a href="{xen:link members/list}" class="navLink">{$tabs.members.title}</a>
    <xen:else />
      <a href="{xen:link somewhere else}" class="navLink">Somewhere else.</a>
    </xen:if>
    
     
  13. James

    James Well-Known Member

    That's pretty much it @Matthew Hawley
     
  14. Matthew Hawley

    Matthew Hawley Well-Known Member

    Didn't work. If BOTH notable members and member lists is enabled I want it to direct to another link.
     
  15. James

    James Well-Known Member

    Code:
    <xen:if is="{$xenOptions.enableNotableMembers}">
      <a href="{$tabs.members.href}" class="navLink">{$tabs.members.title}</a>
    <xen:elseif is="{$xenOptions.enableMemberList}" />
      <a href="{xen:link members/list}" class="navLink">{$tabs.members.title}</a>
    <xen:else />
      <xen:if is="{$xenOptions.enableNotableMembers} && {$xenOptions.enableMemberList}">
    
          <a href="{xen:link somewhere/else}" class="navLink">Somewhere else.</a>
      </xen:if>
    </xen:if>
    

    If notable members: members.href
    If member list: members/list
    If notable members & member list: somewhere/else.
     
    SneakyDave likes this.
  16. Matthew Hawley

    Matthew Hawley Well-Known Member

    Didn't work.
     
  17. James

    James Well-Known Member

    Could you provide some more information? Perhaps debug the code yourself? Which ones work and which ones don't?
     
  18. Matthew Hawley

    Matthew Hawley Well-Known Member

    When I save it in a template I get this:

    EDIT: nvm
     
  19. Matthew Hawley

    Matthew Hawley Well-Known Member

    Okay fixed that syntax error. But now the member navtab disappears.
     
  20. SneakyDave

    SneakyDave Well-Known Member

    Looks to me like James solution should work. Does your version look just like it?

    never mind. Are you missing an
    </xen:if>
    somewhere?
     

Share This Page