Jump to content

[SOLVED] heredoc and conditionals


soycharliente

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.