vBulletin 4 Template Conditionals List

Discussion in 'vBulletin Discussions' started by Nick, Sep 7, 2009.

  1. Nick

    Nick Regular Member

    Joined:
    Jul 27, 2008
    Messages:
    7,444
    Likes Received:
    219
    This is an updated list of conditionals with the syntax used in vBulletin 4. A preview of the syntax was made available on Wayne Luke's site, vBCodex and is the basis from which I have formed this list.

    As of writing, vB 4 isn't even out yet (it's in Alpha testing) so this won't be of use to you just yet, but at least you know it's here and we have it. Might as well add it to your bookmarks now so you have it when you need it. :cool:

    ------

    Viewer is a guest
    Code:
    <vb:if condition="$show['guest']"> </vb:if>
    Viewer is a member
    Code:
    <vb:if condition="$show['member']"> </vb:if>
    Viewer is in a specific usergroup (In this example, 6 is the usergroup ID. You can add more using commas)
    Code:
    <vb:if condition="$is_member_of($bbuserinfo,6)" /></vb:if>
    
    Viewer has a specific User ID (user ID = X)
    Code:
    <vb:if condition="$bbuserinfo['userid'] == X"> </vb:if>
    
    ------


    This list will be updated and maintained as time goes on and more information becomes available. :)
     
  2. Michael

    Michael Regular Member

    Joined:
    Jan 18, 2004
    Messages:
    166
    Likes Received:
    35
    Awesome Nick, I have bookmarked! ;)
     
  3. David

    David Regular Member

    Joined:
    May 30, 2003
    Messages:
    1,088
    Likes Received:
    133
    Location:
    Australia
    any reason why the moved from the easy format of

    <if condition="$show[member]">

    to the new syntax?

    Is the <vb: part of it, so it can be broken down to application specific sections? Like their new CMS

    <cms: if condition="$show['guest']"> </cms:if>
     
  4. Michael

    Michael Regular Member

    Joined:
    Jan 18, 2004
    Messages:
    166
    Likes Received:
    35
    I wouldnt be surprised if that is true, sounds dead on to me :D
     
  5. Nick

    Nick Regular Member

    Joined:
    Jul 27, 2008
    Messages:
    7,444
    Likes Received:
    219
    Wayne explains some of the reasons for the changes, here:

    Template First Look at vBulletin 4 Template Variables - vBCodex
     
  6. twhiting9275

    twhiting9275 Regular Member

    Joined:
    Aug 19, 2009
    Messages:
    372
    Likes Received:
    8
    So in order to help those that can't do the job right, we get stuck with more complicated templates. NOT good
     
  7. kneel

    kneel Regular Member

    Joined:
    Jun 25, 2009
    Messages:
    612
    Likes Received:
    16
    waynes site is an amazing thing...

    thanks for this mane!!
     
  8. cheat-master30

    cheat-master30 Grand Master

    Joined:
    Jul 30, 2009
    Messages:
    789
    Likes Received:
    59
    Thanks for the list Nick. This should help anyone who wants to start converting the simpler modifications on their forum to vBulletin 4 versions.
     
  9. Lynne

    Lynne Regular Member

    Joined:
    May 26, 2009
    Messages:
    333
    Likes Received:
    32
    Location:
    Home Sweet Home!
    How is simply sticking a vb: in front of the if "more complicated". It really is just that simple.
     
  10. Michael

    Michael Regular Member

    Joined:
    Jan 18, 2004
    Messages:
    166
    Likes Received:
    35
    I think adding anything extra to the code which is already there may make it more daunting for beginners to look at. The normal ifs when I first seen them looked really hard to use and with adding vb: or other prefixes it may make the first look of them even more daunting to beginners to the software.
     
  11. Chani

    Chani Grand Master

    Joined:
    Sep 1, 2009
    Messages:
    884
    Likes Received:
    54
    First Name:
    Chani
    I both like this and dislike this.

    I think it'll be cool to be able to add PHP into your templates, but then again, having PHP and HTML separate (gently merged) in vB's current form is one of the things that makes it so easy to edit. (Ever templated a Zen-Cart site??? :eek: )

    As long as the code remains somewhat portable within the site, I'm sure I'll get used to it. :)
     
  12. Wayne Luke

    Wayne Luke Regular Member

    Joined:
    Apr 2, 2009
    Messages:
    992
    Likes Received:
    276
    The problem is the current syntax is invalid and causes validation to fail if you check just a template. However by adding a namespace, you can get around that and it is the proper way to code it.

    The most important part though is that is modular and expandable. The new system allows the use of loops in templates as well as special variable syntax for parsing things like dates, times, and numbers within the templates instead of the PHP Code. This allows you to present more customized experiences to your end users as an administrator without worrying about the PHP code. It allows programmers to give you more tools through addons to customize it even more.

    I doubt there will be PHP in the templates and the new syntax is less PHP-like than before. You'll need to keep your PHP in plugins where it belongs.
     
  13. David

    David Regular Member

    Joined:
    May 30, 2003
    Messages:
    1,088
    Likes Received:
    133
    Location:
    Australia

    Thanks for the update on why the change occurred. I personally don't find it any more difficult to stick vb in front of a condition.
     
  14. Webmist

    Webmist Champion

    Joined:
    Jan 30, 2008
    Messages:
    305
    Likes Received:
    18
    Location:
    US
    First Name:
    Jen
    You know this reminds me of coding for Joomla. :doh:

    Do you think we'll have an actual list of conditionals? I would really like to see that in the release.
     
  15. David

    David Regular Member

    Joined:
    May 30, 2003
    Messages:
    1,088
    Likes Received:
    133
    Location:
    Australia

    From the looks of it, they aren't really changing over current conditionals. I'd imagine there maybe some new ones, and some small changes/tweaks to the current ones, but for the most part it seems its simply a new syntax to prefix the conditional with <vb:
     
  16. Webmist

    Webmist Champion

    Joined:
    Jan 30, 2008
    Messages:
    305
    Likes Received:
    18
    Location:
    US
    First Name:
    Jen
    From the looks of it yeah it shouldn't be to hard to adjust. But you gotta admit it does remind look like one. I like my smarty templates so these type of conditionals wheree....different to get used to.

    I'm actually quite comfortable with the ones for vB.

    Still hope the make a list though.
     
  17. Wayne Luke

    Wayne Luke Regular Member

    Joined:
    Apr 2, 2009
    Messages:
    992
    Likes Received:
    276
    It would be almost impossible list all conditionals available for vBulletin. Any variable available to templates can be used in a conditional and than in any combination allowed for conditional constructs in PHP. Just taking the 458 settings/options and the 60 odd fields in the user table gives you 27480 potential conditionals using the && operator alone. Now not all would be viable or worthwhile but they are possible. That doesn't account for combinations where you can use ==. !=. >=, <=, || or compound conditionals. It also doesn't account for usergroups, permissions, forum information, custom profile fields and about 300 other variables that are available on every page.

    Next you have to account for scope. For instance the userinfo array is not available in the postbit. You have to use the postinfo array.

    Then you would have to account for conditionals that are available in specific templates. Especially since variables have to be registered with templates before they are available in vBulletin. So you won't necessarily be able to use a conditional you saw in the footer inside the header template.

    Needless to say any sort of comprehensive list will be larger than the current vBulletin manual which is over 500 pages. It would take hundreds of hours to produce. The benefit just isn't there. It is much easier to answer threads that ask what conditional to use and a vBulletin staff member posts it for them.
     
    2 people like this.
  18. Michael

    Michael Regular Member

    Joined:
    Jan 18, 2004
    Messages:
    166
    Likes Received:
    35
    Of course a good list of the most commonly used template conditionals is handy, I know I have them bookmarked for when I need to use one of them somewhere. The more advanced ones I tend to ask for on forums.
     
  19. Peacelily

    Peacelily Adept

    Joined:
    Jul 5, 2009
    Messages:
    245
    Likes Received:
    10

    :thumbup:

    Thanks for posting these Nick and to Wayne for the codex. I am always just so dang happy that I have vBulletin that if you told me I had to use these conditionals while wearing purple pajamas with koala bears on them and singing Yankee Doodle Dandy on BlogTV in front of 50,000 people, I'd still be happy as long as I never have to try to do a hack in phpBB ever again as long as I live.
     
  20. Brandon

    Brandon Regular Member

    Joined:
    Jun 1, 2009
    Messages:
    6,602
    Likes Received:
    1,706
    Location:
    Topeka, Kansas
    First Name:
    Brandon
    Great thread, thanks for the info Nick and Wayne
     

Share This Page