Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialtian jin
Courses Plus Student 5,162 Pointswhy do I have to define $section variable in both footer.php and header.php?
otherwise the nav background will be displayed un normally
2 Answers
Steven Walters
10,573 PointsYou define the $section variable in each of your section files. Shirts, contact, etc. Then in the header.php you check to see what what value the $section variable has so the header can indicate what section to highlight.
melissa brown
4,670 Pointsi dont really understand this concept either. i understand that 'in the header.php you check to see what what value the $section variable has so the header can indicate what section to highlight" but then why do we have to define the $section variable in each of the section files. im just not seeing the connection, its seems like you have everything u need in the header file for it to tell u what to do. eg if the section = contact then turn 'on'. so why do u need to add the variables in the section files? eg
<li class="contact <?php if ($section == "contact") {echo "on"; } ?>
Lucas Santos
19,315 PointsLucas Santos
19,315 PointsCan you please be a bit more descriptive and supply us with your code so we can see exactly what you mean and help you. Just a tip for the future, whenever asking a programming question anywhere try to be as descriptive as possible and maybe provide code, you'll get an answer much faster that way.