How to do 3 if conditionials?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • How2Freelance
    New Member
    • Dec 2005
    • 21
    • 3.6.x

    How to do 3 if conditionials?

    <if condition="$forum['forumid'] == 5">
    <td class="alt2" width="71" align="center"><img src="pmw/alternate/forum_$forum[statusicon].gif" alt="" border="0" /></td><td width="2"></td><td class="alt1Active" width="211" align="$stylevar[left]" id="f$forum[forumid]" style="padding-left: 25px;">
    <div>
    <a href="forumdisplay.php?$session[sessionurl]f=$forum[forumid]"><strong>$forum[title]</strong></a>
    <if condition="$show['browsers']"><span class="smallfont">(<phrase 1="$forum[browsers]">$vbphrase[x_viewing]</phrase>)</span></if>
    </div></td><td width="2"></td>
    <td class="alt2" width="69" align="center">$forum[replycount]</td><td width="2"></td></if>
    <if condition="$forum['forumid'] == 6">
    <td class="alt2" width="71" align="center"><img src="pmw/alternate/forum_$forum[statusicon].gif" alt="" border="0" /></td><td width="2"></td><td class="alt1Active" width="211" align="$stylevar[left]" id="f$forum[forumid]" style="padding-left: 25px;">
    <div>
    <a href="forumdisplay.php?$session[sessionurl]f=$forum[forumid]"><strong>$forum[title]</strong></a>
    <if condition="$show['browsers']"><span class="smallfont">(<phrase 1="$forum[browsers]">$vbphrase[x_viewing]</phrase>)</span></if>
    </div></td><td width="2"></td>
    <td class="alt2" width="69" align="center">$forum[replycount]</td><td width="2"></td>
    <else />

    <tr>
    <td><img src="pmw/forumstatus.gif" alt="Forum Icons" /></td><td width="2"></td><td align="center"><img src="pmw/forumnamet.gif" alt="Forum Name" /></td><td width="2"></td><td align="center"><img src="pmw/postst.gif" alt="Posts" /></td><td width="2"></td><td align="center"><img src="pmw/threadst.gif" alt="Threads" /></td><td width="2"></td><td align="center"><img src="pmw/lastpostt.gif" alt="Last Post" /></td><td width="2"></td>
    </tr>
    <tr align="center">
    <td class="alt2" width="71"><img src="$stylevar[imgdir_statusicon]/forum_$forum[statusicon].gif" alt="" border="0" /></td><td width="2" style="border-left: #5C6268 1px solid; border-right: #5C6268 1px solid;"></td>
    <td class="alt1Active" width="211" align="$stylevar[left]" id="f$forum[forumid]" style="padding-left: 25px;">
    <div>
    <a href="forumdisplay.php?$session[sessionurl]f=$forum[forumid]"><strong>$forum[title]</strong></a>
    <if condition="$show['browsers']"><span class="smallfont">(<phrase 1="$forum[browsers]">$vbphrase[x_viewing]</phrase>)</span></if>
    </div>
    <if condition="$show['forumdescription']"><div class="smallfont">$forum[description]</div></if>
    <if condition="$show['forumsubscription']"><div class="smallfont"><strong><a href="subscription.php?$session[sessionurl]do=removesubscription&amp;f=$forum[forumid]" rel="nofollow">$vbphrase[unsubscribe_from_this_forum]</a></strong></div></if>
    <if condition="$show['subforums']"><div class="smallfont" style="margin-top:$stylevar[cellpadding]px"><strong>$vbphrase[subforums]</strong>: $forum[subforums]</div></if>
    </td><td width="2" style="border-left: #5C6268 1px solid; border-right: #5C6268 1px solid;"></td>
    <td class="alt2" width="69">$forum[replycount]</td><td width="2" style="border-left: #5C6268 1px solid; border-right: #5C6268 1px solid;"></td>
    <td class="alt1" width="69">$forum[threadcount]</td><td width="2" style="border-left: #5C6268 1px solid; border-right: #5C6268 1px solid;"></td>
    <td class="alt2" width="139" nowrap="nowrap" style="padding-left: 18px;">$forum[lastpostinfo]</td><td width="2" style="border-left: #5C6268 1px solid; border-right: #5C6268 1px solid;"></td>
    <td></td>
    <if condition="$vboptions['showmoderatorcolumn']">
    <td class="alt1"><div class="smallfont">$forum[moderators]&nbsp;</div></td>
    </if>
    </tr>
    <tr>
    <td align="center"><img src="pmw/forumstatusb.gif" alt="Forum Icons" /></td><td width="2"></td><td align="center"><img src="pmw/forumnameb.gif" alt="Forum Name" /></td><td width="2"></td><td align="center"><img src="pmw/postsb.gif" alt="Posts" /></td><td width="2"></td><td align="center"><img src="pmw/threadsb.gif" alt="Threads" /></td><td width="2"></td><td align="center"><img src="pmw/lastpostb.gif" alt="Last Post" /></td><td width="2"></td>
    </tr>
    $childforumbits
    </if>
    How do I make that work? Is it right now?
  • slappy
    Senior Member
    • Apr 2003
    • 1206

    #2
    Here's some code for 3 "if conditionals"

    Code:
    <if condition="$show['avatar']">
    <!-- check for admin -->
    <if condition="$post[usergroupid]==6">
    <!-- I am an admin so do this -->
    <td class="alt2">
      <table cellpadding="5" cellspacing="0" border="0" width="124" height="82" align="center">
          <tr>
            <td background="$stylevar[imgdir_misc]/badge.png" nowrap="nowrap" no-repeat><img src="$post[avatarurl]" height="64" width="59" align="right"></td>
          </tr>
      </table>
    </td>
    <else />
    <if condition="$post[usergroupid]==X">
    <!-- I am in this usergroup so do this -->
    <td class="alt2">
      <table cellpadding="5" cellspacing="0" border="0" width="124" height="82" align="center">
          <tr>
            <td background="$stylevar[imgdir_misc]/badge2.png" nowrap="nowrap" no-repeat><img src="$post[avatarurl]" height="64" width="59" align="right"></td>
          </tr>
      </table>
    </td>
    <else />
    <!-- I am not in either of those groups so do this -->
      <td class="alt2">
          <a href="member.php?$session[sessionurl]u=$post[userid]"><img src="$post[avatarurl]" $post[avwidth] $post[avheight] alt="<phrase 1="$post[username]">$vbphrase[xs_avatar]</phrase>" border="0" /></a>
      </td>
    </if>
    </if>
    </if>
    The syntax is:

    "if condition...
    else..
    if condition...
    else...
    /if..
    /if...
    /if

    You can add as many else...if conditions as you want, as long as you close them all at the end.

    As peterska2 reminded me in another Thread, the vBulletin standard for if statements is:

    From the vB Manual

    vBulletin template conditionals do not natively support 'else if', but you can easily replicate its behavior by nesting conditionals as follows:

    HTML Code:
    <if condition="$my_variable == 1">
        <p>My variable is equal to one.</p>
    <else />
        <if condition="$my_variable == 2">
            <p>My variable is equal to two.</p>
        <else />
            <p>My variable is equal to neither one nor two.</p>
        </if>
    </if>
    Regards,
    Slappy

    Comment

    widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
    Working...