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 Contact Form & Sending Email Named Routes

Sean Flanagan
Sean Flanagan
33,235 Points

No contact.twig in my work space

Hi.

Does anyone have any idea why I don't have a contact.twig file in my templates folder please? I right-clicked on the sidebar on the left, then clicked Refresh but no contact.twig came up. Thanks.

2 Answers

Mayur Pande
PLUS
Mayur Pande
Courses Plus Student 11,711 Points

Hi Sean, no problem, that will work, below is what I have used;

$app->get("/contact", function() use($app) {
  $app->render("contact.twig"); //change of file extension on this line
})->name('contact');
Sean Flanagan
Sean Flanagan
33,235 Points

Done! Thanks Mayur! :)

Mayur Pande
PLUS
Mayur Pande
Courses Plus Student 11,711 Points

Do you have a contact.html file? If so you need to change the name to contact.twig and then render it through you index.php file

Sean Flanagan
Sean Flanagan
33,235 Points

Hi Mayur. Thanks for your help. My contact.html file now has the .twig extension. And I've changed a line below to reflect this:

$app->get("/contact", function() use($app) {
  $app->render("contact.twig"); //change of file extension on this line
});

Have I got it right?