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

Josh Naylor
Josh Naylor
19,341 Points

How would you do a route of multiple levels without breaking path to CSS?

When I write out a route like this...

<?php
$app->get('/services/service-name', function() use($app) {
    $app->render('service-name.twig');
})->name('service-name');

The paths to the CSS and JS break and start loading from "example.com/services/css..." instead of "example.com/css...".

How would you use a route with multiple parts?

Edited to format code.

Deleted duplicate question.

2 Answers

Josh Naylor
Josh Naylor
19,341 Points

Thanks, Ted!

I did it in a similar fashion, using the helper from Twig:

<link rel="stylesheet" href="{{ baseUrl() }}/css/master.css">

That is better.

The path is set in the main.twig file. You could also add the DIR constant to help ensure the path stays correct. It would look something like this:

<link rel="stylesheet" href="<?php __DIR__; ?>/css/master.css">