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 trialjared garcia
1,295 PointsHow are you using $pageTitle and $section without including the catalog.php where you are setting the variables?
How are you using $pageTitle and $section without including the catalog.php where you are setting the variables?
2 Answers
Mike Dion
3,788 PointsIt's being defined in a different file before the header is included. For example, on suggest.php (code below - couldn't paste a screenshot) the $pageTitle variable is defined just before header.php is included:
// From suggest.php
<?php
$pageTitle = "Suggest a Media Item"; ?>
include("inc/header.php");
<div class="section page">
<h1>Suggest a Media Item</h1>
</div>
<?php include("inc/footer.php"); ?>
Often a lot of programmatic steps will be taken before including the header (setting the page title, setting meta, instantiating objects that will be used throughout the page, etc).
I used to struggle with the idea that header.php should be the first thing and was writing some pretty awful conditional statements to make that work 5 years ago. Thinking of the header as a component rather than following the visual cue from the website that it's the "top of the page" helped break some bad habits for me.
Jonathan Grieve
Treehouse Moderator 91,253 PointsTo add to what Mike said above you want to include a reference to the variable in header.php
so instead of the hard coded text, you'd echo the variable like this
<h1> <?php> echo $pageTitle <?php? </h1>
That will then pick up the variable defined at the top of on an individual php template e.g. home.php