doubledee Posted June 23, 2012 Share Posted June 23, 2012 I have a block of navigation tabs that I need to place inside of PHP so I can toggle whether the tabs appear or not. Here is a snippet of what I am trying to do, but it is messy and not compiling or whatever you call it... <?php echo "<ul id='profileMenu'> <li id='firstTab'>" . (isset($tabName=='about-me') ? class='current' : '') . "</li> </ul>"; ?> How can I both FIX THIS and CLEAN IT UP - if that is possible?! Thanks, Debbie Quote Link to comment https://forums.phpfreaks.com/topic/264672-problem-with-quotes/ Share on other sites More sharing options...
doubledee Posted June 23, 2012 Author Share Posted June 23, 2012 I had an ISSET in there accidently. This seems to work... <?php echo "<ul id='profileMenu'> <li id='firstTab'" . (($tabName=='about-me') ? " class='current'" : "") . "> Some Item </li> </ul>"; ?> Debbie Quote Link to comment https://forums.phpfreaks.com/topic/264672-problem-with-quotes/#findComment-1356481 Share on other sites More sharing options...
.josh Posted June 23, 2012 Share Posted June 23, 2012 in your OP code: <?php echo "<ul id='profileMenu'> <li id='firstTab'>" . (isset($tabName=='about-me') ? class='current' : '') . "</li> </ul>"; ?> 1) Looks like your ternary is supposed to add something inside your opening "li" tag but you closed it before the ternary 2) isset syntax is wrong. isset takes variables for arguments, not expressions. 3) Did not wrap quotes around the strings you are trying to add to the "li" tag 4) Did not properly wrap the ternary in parenthesis Here is what the code should look like <?php echo "<ul id='profileMenu'> <li id='firstTab'" . ((isset($tabName)&&$tabName=='about-me') ? " class='current'" : '') . "></li> </ul>"; ?> Couple notes/opinions/suggestions: 1) Issues like this won't happen if you separate your logic from your content. Put that ternary in a variable before the echo and then include the variable in the echo. 2) If you want to echo things multi-line like that, you might wanna look into using heredoc syntax. This will only really work out for you if you follow suggestion #1. Quote Link to comment https://forums.phpfreaks.com/topic/264672-problem-with-quotes/#findComment-1356501 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.