• Register
    • Help

    striker  0 Items
    Currently Supporting
    • Home
    • News
    • Forum
      • Try XenForo Demo
      • New Posts
      • FAQ
      • Calendar
      • Community
        • Groups
        • Albums
        • Member List
      • Forum Actions
        • Mark Forums Read
      • Quick Links
        • Today's Posts
        • Who's Online
      • Sponsor
        • Sponsor a Feature
        • List of Donors
    • Wiki
    • Support
    • What's New?
    • Buy Now
    • Manual
    • 
    • Forum
    • VaultWiki How-Tos
    • VaultWiki Questions
    • Nested If/Else statements

    1. Welcome to VaultWiki.org, home of the wiki add-on for vBulletin and XenForo!

      VaultWiki allows your existing forum users to collaborate on creating and managing a site's content pages. VaultWiki is a fully-featured and fully-supported wiki solution for vBulletin and XenForo.

      The VaultWiki Team encourages you to join our community of forum administrators and check out VaultWiki for yourself.

    Results 1 to 9 of 9

    Thread: Nested If/Else statements

    • Thread Tools
      • Show Printable Version
    1. April 4, 2022 #1
      FrankPereiro
      • View Profile
      • View Forum Posts
      • View Blog Entries
      • View Articles
      FrankPereiro is offline
      Junior Member
      Join Date
      March 12, 2022
      Posts
      8
      Rep Power
      0

      Nested If/Else statements

      Hi there,

      I wonder if anyone can help nesting several If/Else statements in VW...

      Thanks
      Reply With Quote Reply With Quote

    2. April 4, 2022 #2
      pegasus
      • View Profile
      • View Forum Posts
      • View Blog Entries
      • Visit Homepage
      • View Articles
      pegasus is offline
      VaultWiki Team
      Join Date
      March 28, 2004
      Location
      New York, NY
      Posts
      2,959
      Blog Entries
      18
      Rep Power
      688
      Hi, please explain what you need to do.

      VaultWiki's IF condition can only test 1 expression at a time (such as A == B), or a not-empty on a list of parameters (A B C D) which is true if any of A,B,C,D has content. So for more complicated expressions, like a logical AND, you would need to use nested IF statements.

      You can simplify the IF statements around content and avoid confusion by making new local variables.

      Code:
      [if="{{{x}}}==1"][if="{{{y}}}==2"]
      [var]set|X1_and_Y2|1[/var]
      [/if][/if][comment]
      
      ...
      
      [/comment][if="[var]get|X1_and_Y2[/var]"]
      the content
      [/if]
      - lead developer for VaultWiki
      Reply With Quote Reply With Quote

    3. April 5, 2022 #3
      FrankPereiro
      • View Profile
      • View Forum Posts
      • View Blog Entries
      • View Articles
      FrankPereiro is offline
      Junior Member
      Join Date
      March 12, 2022
      Posts
      8
      Rep Power
      0
      Hi pegasus, thanks for your reply...

      What I wish to accomplish is something like this (I'm making this up just to let you know what I'd like to do):

      Code:
      [if="{{{1}}}=One"]
      [if="{{{2}}}=Two"]
      [if="{{{3}}}=Three"]
      [if="{{{4}}}=Four"]
      [else]Five[/else]
      [/if]
      [/if]
      [/if]
      [/if]
      What I'm trying to say it's that need to know how to nest these tags...

      Thanks
      Reply With Quote Reply With Quote

    4. April 5, 2022 #4
      pegasus
      • View Profile
      • View Forum Posts
      • View Blog Entries
      • Visit Homepage
      • View Articles
      pegasus is offline
      VaultWiki Team
      Join Date
      March 28, 2004
      Location
      New York, NY
      Posts
      2,959
      Blog Entries
      18
      Rep Power
      688
      If 1 == One AND 2 == Two, but nothing else matches, then should the result should be 5?

      You do not use opening and closing for ELSE. It is a separator and it gets self-closed. You use it once, like so:
      Code:
      [if="{{{1}}}==One"]
      One
      [else /]
      Five
      [/if]
      If you want ELSE-5 for every IF in the stack, then the example in my previous post should make it easier:
      Code:
      [if="{{{1}}}==One"]
      [if="{{{2}}}==Two"]
      [if="{{{3}}}==Three"]
      [if="{{{4}}}==Four"]
      [var]set|all_four|1[/var]
      [/if][/if][/if][/if]
      
      [if="[var]get|all_four[/var]"]
      ...
      [else /]
      Five
      [/if]
      If you want {{{1}}}==One, else if {{{2}}}==Two, else if ... etc
      Then you have to nest all these tags like so:
      Code:
      [if="{{{1}}}==One"]...
      
      [else /][if="{{{2}}}==Two"]
      
      [else /][if="{{{3}}}==Three"]
      
      [else /][if="{{{4}}}==Four"]
      
      [else /]
      Five
      [/if][/if][/if][/if]
      - lead developer for VaultWiki
      Reply With Quote Reply With Quote

    5. April 6, 2022 #5
      FrankPereiro
      • View Profile
      • View Forum Posts
      • View Blog Entries
      • View Articles
      FrankPereiro is offline
      Junior Member
      Join Date
      March 12, 2022
      Posts
      8
      Rep Power
      0

      Thumbs up

      Hi there, pegasus

      Thanks again for your patience with me.

      I think this is the code I need, the "if else statement"

      Code:
      [if="{{{1}}}==One"]...
      
      [else /][if="{{{2}}}==Two"]
      
      [else /][if="{{{3}}}==Three"]
      
      [else /][if="{{{4}}}==Four"]
      
      [else /]
      Five
      [/if][/if][/if][/if]
      I will text it later today and confirm, but this code is the one that makes sense to me.

      Thanks again
      Reply With Quote Reply With Quote

    6. April 6, 2022 #6
      FrankPereiro
      • View Profile
      • View Forum Posts
      • View Blog Entries
      • View Articles
      FrankPereiro is offline
      Junior Member
      Join Date
      March 12, 2022
      Posts
      8
      Rep Power
      0
      I think the code is working, but I have to check it out tomorrow to make sure,

      I have another question, can VW make simple math operations? What I need is to subtract the current year minus a given year, like 2022 minus 1970, for example, how can I do that?

      Thanks
      Reply With Quote Reply With Quote

    7. April 6, 2022 #7
      pegasus
      • View Profile
      • View Forum Posts
      • View Blog Entries
      • Visit Homepage
      • View Articles
      pegasus is offline
      VaultWiki Team
      Join Date
      March 28, 2004
      Location
      New York, NY
      Posts
      2,959
      Blog Entries
      18
      Rep Power
      688
      Sadly I don't think we have a way to do math through BB-Codes.
      - lead developer for VaultWiki
      Reply With Quote Reply With Quote

    8. April 7, 2022 #8
      FrankPereiro
      • View Profile
      • View Forum Posts
      • View Blog Entries
      • View Articles
      FrankPereiro is offline
      Junior Member
      Join Date
      March 12, 2022
      Posts
      8
      Rep Power
      0
      Quote Originally Posted by pegasus View Post
      Sadly I don't think we have a way to do math through BB-Codes.
      I thought that I could be able to do basic math operations through variables or something like that in VW...

      By the way, the "if else" code you told me is working great. I want it to create a little dynamic content depending on the day of the year. It's gonna be a long long code but I think it's going to work just fine. I made a test and it worked.

      I'm going to ask in the XenForo board if it's possible to do dinner basic math operations. What I need is a way to make subtractions (subtract the current year and the year of birth to calculate the age of a person)...

      Thanks pegasus, I'll bring the codes of the things I'm trying to accomplish, in some other time, in case others want to do something like that in their wikis.

      Regards
      Reply With Quote Reply With Quote

    9. April 10, 2022 #9
      FrankPereiro
      • View Profile
      • View Forum Posts
      • View Blog Entries
      • View Articles
      FrankPereiro is offline
      Junior Member
      Join Date
      March 12, 2022
      Posts
      8
      Rep Power
      0
      Would it be possible to make a subtraction from the current year minus a number I specify?

      Is there a wiki syntax for that?
      Last edited by FrankPereiro; April 11, 2022 at 5:25 PM.
      Reply With Quote Reply With Quote

    Similar Threads

    1. How do I Create Nested Chapters in a Book
      By ricktas in forum VaultWiki Questions
      Replies: 4
      Last Post: January 8, 2011, 4:07 AM

    Tags for this Thread

    if/else, nested, nesting, statements

    View Tag Cloud

    Bookmarks

    Bookmarks
    • Submit to Digg Digg
    • Submit to del.icio.us del.icio.us
    • Submit to StumbleUpon StumbleUpon
    • Submit to Google Google

    Posting Permissions

    • 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 Off
    • [VIDEO] code is
    • HTML code is Off

    Forum Rules

    • Contact Us
    • License Agreement
    • Privacy
    • Terms
    • Top
    All times are GMT -4. The time now is 2:11 PM.
    This site uses cookies to help personalize content, to tailor your experience, and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Learn more… Accept Remind me later
  • striker
    Powered by vBulletin® Version 4.2.5 Beta 2
    Copyright © 2025 vBulletin Solutions Inc. All rights reserved.
    Search Engine Optimisation provided by DragonByte SEO (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
    Copyright © 2008 - 2024 VaultWiki Team, Cracked Egg Studios, LLC.