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
Davey Wright
1,381 PointsTrouble with MAMP reloading
Hey there, I am currently working on "build a simple php application" and I have installed mamp fine and adjusted the preferences as instructed and I have no problem loading the files and viewing them on the server/browser.
However I am making changes to the html and writing some of the php code that is being taught. But I have to click the refresh several times and jump around the site to different pages to see the changes being made.
In particular I am having trouble with the title variable, I have triple checked my work to make sure it is written exactly how it is taught, but the title in the tab never changes. Even when I completely changed the title on all of the pages from the original, the original title is still displayed. ???? Sorry if this sounds confusing, but i am super confused also.
4 Answers
Victor Arellano
12,045 PointsHello Davey.
Could you submit your code? I'll see if I can help.
Davey Wright
1,381 PointsHey Victor thanks for your reply. here is the code I filled the paragraphs with just random words so it wouldn't take up to much space. also one more question you may be able to answer easily and may be common sense. but where would i put the ending body and html tag? I have this code on three separate pages in sublime text, and am a little confused whether or not i need to add html, body, title tags to each separate page?
<html lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title><?php echo $pageTitle; ?></title> <link rel="stylesheet" href="css/home.css" type="text/css" media="screen"> </head> <body> <div id="container"> <div id="home" class="grid">
<img class="collage" src="images/collage.png">
<h1><a href="blog.php">Davey & Phoebe</a></h1>
<p>blah blah blah blah blah</p>
<ul class="nav">
<li><a href="#">Midwivery</a></li>
<li><a href="#">Youth</a></li>
<li><a href="support.php">Support</a><li>
</ul>
</div>
<?php $pageTitle = "blog"; include('include/home.php'); ?>
<link rel="stylesheet" href="css/blog.css" type="text/css" media="screen">
<div id="blog" class="grid">
<img src="images/BLOG_1.jpg">
<img src="images/BLOG_2.jpg">
<img src="images/fire.jpg">
</div>
</div>
<?php $pageTitle = 'Support'; include('include/home.php'); ?>
<div class="section page">
<h1>Support</h1>
<p>jingle </p>
</div>
Victor Arellano
12,045 PointsThe following is a very basic example of how php includes work for the header and the footer of a page.
In order for the title to appear you must specify it first at the beginning of each php file, before including the header. If you include the header before declaring the title, it won't work because it won't know the value of the $pageTitle variable. Also, the page title (which appears in the browser tab) must be in the <head> section. If you're going to work with other elements that change in the header from one page to another (like the $section variable from the video example) you must spicify it at the top of the page too.
index.php
<?php
$pageTitle = "Home";
include("includes/header.php"); // Includes the common header
?>
<div class="content">
Page specific content goes here
</div>
<?php
include("includes/footer.php"); // Includes the common footer
?>
This is the header file. It prints the value of the $pageTitle variable and the common header for all your pages. It contains the doctype declaration and the initial <html> and <body> tags.
header.php
<!DOCTYPE html>
<html>
<head>
<title><?php echo $pageTitle; ?></title>
</head>
<body>
<div class="header">
Common header goes here
</div>
This is the footer page. It displays the common footer and contains the closing </body> and </html> tags.
footer.php
<div class="footer">
Common footer goes here
</div>
</body>
</html>
Hope this helps.
Davey Wright
1,381 Pointsawesome thanks yeah this helps!