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 trial

PHP Build a Simple PHP Application Creating the Menu and Footer Adding Active States to the Navigation

why do I have to define $section variable in both footer.php and header.php?

otherwise the nav background will be displayed un normally

Lucas Santos
Lucas Santos
19,315 Points

Can 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.

2 Answers

Steven Walters
Steven Walters
10,573 Points

You 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
melissa brown
4,670 Points

i 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"; } ?>