soycharliente Posted December 4, 2008 Share Posted December 4, 2008 This bit of code doesn't work. What can I do such that the middle part is only inserted when the condition is true? nav.php: <?php $nav = <<<NAV <li><a href="/test/">Home</a></li> <li><a href="#">Link</a></li> NAV; if ($tripnav == "about"){ $nav .= <<<NAV <ul id="tripsubnavlist"> <li><a href="#">Link</a></li> <li><a href="#">Link</a></li> </ul> NAV; } $nav .= <<<NAV <li><a href="#">Link</a></li> <li><a href="#">Link</a></li> NAV; echo $nav; ?> index.php: <?php $tripnav = "about"; ?> <html> <body> <ul id="navlist"> <?php include("lib/navigation.php"); ?> </ul> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/135547-solved-heredoc-and-conditionals/ Share on other sites More sharing options...
genericnumber1 Posted December 4, 2008 Share Posted December 4, 2008 The end of a heredoc statement must be at the left margin.. which isn't the case for yours inside of the if statement. Move that "NAV" to the left margin (no white space!) and it should be fine. Link to comment https://forums.phpfreaks.com/topic/135547-solved-heredoc-and-conditionals/#findComment-706126 Share on other sites More sharing options...
soycharliente Posted December 4, 2008 Author Share Posted December 4, 2008 That did the trick. Thanks. REMEMBER! NO WHITE SPACE! Link to comment https://forums.phpfreaks.com/topic/135547-solved-heredoc-and-conditionals/#findComment-706130 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.