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 trialJosh Naylor
19,341 PointsHow 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?
Ted Sumner
Courses Plus Student 17,967 PointsDeleted duplicate question.
2 Answers
Josh Naylor
19,341 PointsThanks, Ted!
I did it in a similar fashion, using the helper from Twig:
<link rel="stylesheet" href="{{ baseUrl() }}/css/master.css">
Ted Sumner
Courses Plus Student 17,967 PointsThat is better.
Ted Sumner
Courses Plus Student 17,967 PointsThe 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">
Ted Sumner
Courses Plus Student 17,967 PointsTed Sumner
Courses Plus Student 17,967 PointsEdited to format code.