Kitty Juice
New member
I am having trouble taking a variable from my include and echoing it.
It's a nav bar that determines what css class to use based on the file name.
template.php:
<?php
$nav_bar =
"<div id=nav>
<a href=index.php><div class=<?php if($page == index.php){echo active}else{echo button}?>>Home</div></a>
<a href=forum.php><div class=<?php if($page == forum.php){echo active}else{echo button}?>>Forum</div></a>
";
?>
index.php:
<?php
include("template.php");
$page = basename($_SERVER['SCRIPT_NAME']);
echo "$nav_bar";
?>
The problem is that when I echo "$nav_bar" it takes it literally and doesn't execute any of the php. How can i make it execute? Using it like this give me the undefined variable error ($page).
How can i make this work?
-Thank you!
-Aus
It's a nav bar that determines what css class to use based on the file name.
template.php:
<?php
$nav_bar =
"<div id=nav>
<a href=index.php><div class=<?php if($page == index.php){echo active}else{echo button}?>>Home</div></a>
<a href=forum.php><div class=<?php if($page == forum.php){echo active}else{echo button}?>>Forum</div></a>
";
?>
index.php:
<?php
include("template.php");
$page = basename($_SERVER['SCRIPT_NAME']);
echo "$nav_bar";
?>
The problem is that when I echo "$nav_bar" it takes it literally and doesn't execute any of the php. How can i make it execute? Using it like this give me the undefined variable error ($page).
How can i make this work?
-Thank you!
-Aus