0

Can someone please tell me why this php If-statement is displaying the html when the condition is false?

<?php if ($sidebar['blog_default_layout'] == "Left Sidebar") : ?>
    <aside class="sidebar span3" role="complementary">
        <?php get_sidebar( 'blog-sidebar' ); ?>
    </aside>
<?php endif ?>  

According to: Can HTML be embedded inside PHP “if” statement? this shouldn't display the html since the condition is not true.

The <?php get_sidebar( 'blog-sidebar' ); ?> between the html doesn't display, as it shouldn't.

Community
  • 1
  • 1
teamcrisis
  • 709
  • 1
  • 6
  • 14
  • 5
    What `var_dump($sidebar['blog_default_layout'])` shows? – raina77ow Jul 12 '13 at 21:34
  • 2
    It should definitely not display the HTML, which means that most likely the condition is indeed true. – Jon Jul 12 '13 at 21:34
  • are you sure the condition's false? What's the value in that var? – Marc B Jul 12 '13 at 21:34
  • Your `if` statement is returning the html b/c it is true. – Chris78 Jul 12 '13 at 21:35
  • @raina77ow var_dump shows: string(13) "Right Sidebar" – teamcrisis Jul 12 '13 at 21:36
  • 1
    var_dump($sidebar['blog_default_layout']); right before the condition? – Dany Caissy Jul 12 '13 at 21:37
  • ... or immediately after that `if` condition. ) But it's pointless actually: it's two strings, they will get compared as strings, so it should be `'Right Sidebar'` at this point. I wonder, though, what can change it. Is it Wordpress? Or some other blog engine? – raina77ow Jul 12 '13 at 21:37
  • You may want to dump that inside the if statement. B/c if it was false it would not execute. – Chris78 Jul 12 '13 at 21:37
  • @DanyCaissy I placed var_dump immediately before and immediately after...shows the same in both places. – teamcrisis Jul 12 '13 at 21:40
  • Ok, we're doing basic debugging here at the moment... why don't you just check that the code DOES go into that `if`? Remove that 'aside' part, then place something really straight-forward - like `die(111)`, for example. – raina77ow Jul 12 '13 at 21:43
  • @raina77ow yes it is wordpress. I have another if-statement later on the page for Right Sidebar. That evaluates true and displays the html and the content as it should, but the Left Sidebar still displays html, but not the content inside. Left Sidebar should not display anything as it's false, right? – teamcrisis Jul 12 '13 at 21:43
  • Sorry, I don't get it: what do you mean by 'displays html'? Do you sse this ` – raina77ow Jul 12 '13 at 21:44
  • 3
    How do you know that the "displayed html" is the one corresponding to this code? I'm almost sure that you are seeing another piece of html, not this one. Have you tried changing a bit of this html (i.e. change the classes "sidebar span3" to "sidebar span3 test") and checking if the change is reflected in what you see? Also, can you please show us the full code of your script (even here or pasted somewhere else)? – Racso Jul 12 '13 at 21:49
  • @Racso Indeed. I think I have debugged this to being something outside of this if-statement. I believe the problem is related to another file. – teamcrisis Jul 12 '13 at 22:22
  • Thanks everyone for your help. I think I have this problems solved. It appears to be some leftover code in another file causing the issue. Stupid mistake on my part. – teamcrisis Jul 12 '13 at 22:24

0 Answers0