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

Darren Peyou-Ndi
Darren Peyou-Ndi
6,154 Points

Htaccess and why is my css code broken when I go to contact page?

I am using Xammpp to run my website. My index.php is as follows: <?php require "vendor/autoload.php";

$app = new \Slim\Slim( array( 'view' => new \Slim\Views\Twig() )); $view = $app->view(); $view->parserOptions = array( 'debug' => true //'cache' => dirname(FILE) . '/cache' ); $view->parserExtensions = array( new \Slim\Views\TwigExtension(), ); $app->get('/', function() use($app)

{$app->render('about.twig'); });

$app->get('/contact', function() use($app)

{$app->render('contact.twig'); });

$app->run();

?>

My main template with twig; main.twig is as follows: <!doctype html>

<html lang="en"> <head> {% block head %} <meta charset="utf-8"> <title> {% block title %} Ralph Waldo Emerson{% endblock title %}</title> <meta name="description" content="Ralph Waldo Emerson"> <meta name="author" content="Treehouse"> <link href='http://fonts.googleapis.com/css?family=Roboto:400,700' rel='stylesheet' type='text/css'> <link rel="stylesheet" href="css/master.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script src="js/global.js"></script> {% endblock head %} </head>

<body> <!-- <div id="feedback" class="success"> <h3>Success!</h3> <p>You're reading all about Emerson.</p> </div> -->

<header> <h1>Ralph Waldo Emerson</h1> <nav> <a href="index.html" class="selected">About</a> <a href="contact.html">Contact</a> </nav> </header>

<div class="emerson"> {% block hero %}<img src="images/emerson.jpg" alt="Picture of Ralph Waldo Emerson"> {% endblock hero %} </div>

<main> {% block content %} {% endblock content %} </main>

<footer> {% block footer %} <p>A project from <strong><a href="http://teamtreehouse.com">Treehouse</a></strong></p> <nav> <a href="index.html" class="selected">About</a> <a href="contact.html">Contact</a> </nav> {% endblock footer %} </footer>

</body> </html>

My about.twig which is my homepage works just fine but my contact.twig which is my contact page doesn't at all; the css is broken. I know my href links still link to html files but that isn't my concern right now. Lastly, my htaccess file:

RewriteEngine On

Some hosts may require you to use the RewriteBase directive.

If you need to use the RewriteBase directive, it should be the

absolute physical path to the directory that contains this htaccess file.

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [QSA,L]

Marissa Richardson
Marissa Richardson
47,542 Points

I haven't worked on this project just yet, and I only use MAMP, but here's what I'm thinking:

  • You used an extension from the main.twig file to create the about.twig file like this -

{% extends 'main.twig' %}

{% block content %} //main content {% endblock content %}

Hampton said to do the same for the contact.twig file, but didn't show the exact steps for it. So maybe check that out.

  • Did you create name routes for your URLs (maybe not important)?

index.php

$app->get('/', function() use($app) { $app->render('about.twig'); }) ->name('home');

$app->get('/contact', function() use($app) { $app->render('contact.twig'); })->name('contact');

$app->run();

  • Did you sanitize the data from your contact page form (again maybe not important for your issue)?

1 Answer

Darren Peyou-Ndi
Darren Peyou-Ndi
6,154 Points

Hey Marissa, thanks for answering! It mainly was sanitizing so I got it to work.