Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Will nested IF statements work?
brad-t Offline
Member
***
Posts: 120
Joined: Apr 2011
Post: #1
Will nested IF statements work?
I'm using this in usercp_nav to display two different menus depending on which page you are viewing. The if statements for the CSS classes and inbox unread count were working before being nested in another IF -- is this a problem? Are nested IF disallowed?

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<!-- User CP Menu -->

<if THIS_SCRIPT == "usercp.php" then>
<div class="cp_menu"><a href="/usercp.php"<if $mybb->input['action'] == '' ||  $mybb->input['action'] == 'changename' ||  $mybb->input['action'] == 'editsig' ||  $mybb->input['action'] == 'email'  || $mybb->input['action'] == 'password' then> class="current"</if>>Profile & Settings</a> <a href="/usercp.php?action=editlists"<if $mybb->input['action'] == 'editlists' then> class="current"</if>>Friends and Foes</a> <a href="/usercp.php?action=drafts"<if $mybb->input['action'] == 'drafts' then> class="current"</if>>Drafts</a> <a href="/usercp.php?action=subscriptions"<if $mybb->input['action'] == 'subscriptions' then> class="current"</if>>Following</a> <a href="/User-{$mybb->user['username']}" style="float: right;">Go to profile ➜</a></div></if>

<!-- Private Messages Menu -->

<if THIS_SCRIPT == "private.php" then>

<td valign="top" style="width: 200px; float: left; margin-right: 20px;">
<table border="0" cellspacing="0" cellpadding="0" class="insetbox messagenav" style="margin-bottom: 13px;">
	<tr>
		<td style="padding: 0px;">

<a href="/private.php?action=send" class="button bigbutton" style="display: block;">New Message</a><br />

<if $mybb->user['pms_unread'] == 0 then>
<a href="/private.php?fid=1" class="biglink <if $folder == 1 then>current</if>" style="display: block;">Inbox</a>

<else>
<a href="/private.php?fid=1" class="biglink <if $folder == 1 then>current</if>" style="display: block; font-weight: bold;">Inbox ({$lang->welcome_pms_usage})</a>
</if>

<a href="/private.php?fid=2" class="biglink <if $folder == 2 then>current</if>" style="display: block;">Sent</a>
<a href="/private.php?fid=3" class="biglink <if $folder == 3 then>current</if>" style="display: block;">Drafts</a>
<a href="/private.php?fid=4" class="biglink <if $folder == 4 then>current</if>" style="display: block;">Trash</a>
<br />
<div class="smalltext">
<a href="/private.php?action=tracking" style="display: block;">Track Messages</a>
<a href="/private.php?action=export" style="display: block;">Download Messages</a>
<a href="/private.php?action=empty" style="display: block;">Empty Folders</a>
</div>

</td></tr>

</table>
</td>
</if>

06-23-2012 05:09 AM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #2
RE: Will nested IF statements work?
Do you mean that the 'current' class in private.php page doesn't work?

(This post was last modified: 06-23-2012 07:06 AM by RateU.)
06-23-2012 07:05 AM
Find all posts by this user Quote this message in a reply
brad-t Offline
Member
***
Posts: 120
Joined: Apr 2011
Post: #3
RE: Will nested IF statements work?
Correct. Was working before I put it within another If.
06-23-2012 07:53 AM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #4
RE: Will nested IF statements work?
Try using $mybb->input['fid'] ?

06-23-2012 07:57 AM
Find all posts by this user Quote this message in a reply
brad-t Offline
Member
***
Posts: 120
Joined: Apr 2011
Post: #5
RE: Will nested IF statements work?
That works, thanks!
06-23-2012 08:48 AM
Find all posts by this user Quote this message in a reply
brad-t Offline
Member
***
Posts: 120
Joined: Apr 2011
Post: #6
RE: Will nested IF statements work?
How to show "current" if there is no input (e.g. just private.php?) this was working in the old code but not in the new one.
06-27-2012 12:25 AM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #7
RE: Will nested IF statements work?
Depends on the input. If it is fid only, you can try using something like

Code:
<if !$mybb->input['fid'] then>current</if>

If you have too many conditionals there, maybe it is better if you try to simplify it (if there is a chance to do that)?


06-27-2012 05:21 AM
Find all posts by this user Quote this message in a reply
brad-t Offline
Member
***
Posts: 120
Joined: Apr 2011
Post: #8
RE: Will nested IF statements work?
Nope, this doesn't work either, since it sets it as Current on any page where you input. I basically want it to show as current when there is NO input, simply private.php landing page. It worked in the original before I wrapped it in an if ...
06-27-2012 09:51 AM
Find all posts by this user Quote this message in a reply
brad-t Offline
Member
***
Posts: 120
Joined: Apr 2011
Post: #9
RE: Will nested IF statements work?
Fixed it with this:

Code:
<if $mybb->input['fid'] == '' || $mybb->input['fid'] == 1 then>current</if>


Thanks for your help!

06-27-2012 11:52 AM
Find all posts by this user Quote this message in a reply
brad-t Offline
Member
***
Posts: 120
Joined: Apr 2011
Post: #10
RE: Will nested IF statements work?
Ahh, but this doesn't work if you are on pages with other actions, like read, export, etc. ... inbox will still be highlighted.

I just need a way to say "if this is index.php with no inputs or actions". For now, I'll just change header link to address fid.
(This post was last modified: 06-27-2012 01:57 PM by brad-t.)
06-27-2012 01:54 PM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: