Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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