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 Building Websites with PHP Slim Basics & Twig Templates Including & Rendering

Sean Flanagan
Sean Flanagan
33,235 Points

Where's my contact.html page?

Hi. The contact.html page only produces a 404 error when I call it up. I'm near the end of the video, over 7 minutes.

I'll paste the code for my index.php below, along with a snapshot:

<?php

require __DIR__ . '/vendor/autoload.php';
date_default_timezone_set("Europe/London");

//$log = new Logger('name');
//$log->pushHandler(new StreamHandler('app.txt', Monolog\Logger::WARNING));
//$log->addWarning('Oh No.');

$app = new \Slim\Slim();

$app->get("/", function() use($app) {
  $app->render("index.html");
});

$app->get("/contact", function() use($app) {
  $app->render("contact.html");
});

$app->run();

?>

Snapshot: https://w.trhou.se/z1byyutm90

Here's another snapshot, this one of my index.html inside my templates folder:

https://w.trhou.se/tvelc5oiof

Thanks in advance for any help. :)

Sean Flanagan
Sean Flanagan
33,235 Points

Hi Kabir. It's still not working.

Contact.html

Line 27:

<a href="/">About</a>

Line 61:

<a  href="contact" class="selected">Contact</a>

Index.html

Line 27:

<a href="/">About</a>

Line 56:

<a href="index" class="selected">About</a>

Have I got it right? Thanks.

kabir k
kabir k
Courses Plus Student 18,036 Points

Hi Sean,

No, it's not edited correctly. Here's the link to my project's snapshot so you can check in the templates folder and see how I did it. You'll see some HTML comments beside the code lines. Just ignore those.

For example, I edited the <a> tags in lines 27, 28, 61, and 62 in the contact.html file and did similar things in index.html as well (both in the templates folder)

Hope that helps.

kabir k
kabir k
Courses Plus Student 18,036 Points

There are 4 <a> tags that you need to locate and edit in each of these files. You only did 2 in each file and some of them like line 56 is not done correctly.

A) contact.html

Line 27:

<a href="/">About</a>

Line 28:

<a  href="contact" class="selected">Contact</a>

Line 61:

<a href="/">About</a>

Line 62:

<a  href="contact" class="selected">Contact</a>

B) index.html

Line 27:

<a href="/" class="selected">About</a>

Line 28:

<a href="contact">Contact</a>

Line 56:

<a href="/" class="selected">About</a>

Line 57:

<a href="contact">Contact</a>

Just change what you have originally to what I have typed above.

2 Answers

kabir k
PLUS
kabir k
Courses Plus Student 18,036 Points

To get to the contact page in your browser, after the .com type just /contact NOT /contact.html

And to link to contact page from the header on your home page, you'll have to do some modifications in both the index.html and contact.html file in the template folder.

Hope that helps.

Sean Flanagan
Sean Flanagan
33,235 Points

It's helped. I typed in /contact and it worked. Thanks.

You said that to link to contact.html from the home page's header, I'll have to modify both index.html and contact.html. Is there any specific part of this video that shows me how to do this?

kabir k
kabir k
Courses Plus Student 18,036 Points

You're welcome.

I don't think it's in the video. Maybe, it is mentioned in the next video though.

If you would like to change it, though, I don't think you're required to change it at this point but I believe you could go to the templates folder in workspaces and inside the contact.html file

Locate and change both the a tags at lines 27 and 61, from this:

<a href="index.html">About</a>
<a  href="contact.html" class="selected">Contact</a>

to this:

<a href="/">About</a>
<a  href="contact" class="selected">Contact</a>

And do the same for the index.html file of the same folder at line 27 and 56

NOTE: you might wanna save a copy of both files' content (somewhere else) in case you mess it up or wanna revert back to it or you could undo it with Cmd + Z

Sean Flanagan
Sean Flanagan
33,235 Points

Hi Kabir. I've done as you said and it's worked perfectly. Thank you for all your help which has earned you Best Answer. :)

kabir k
kabir k
Courses Plus Student 18,036 Points

You're welcome. Glad to be of help. Thanks.