# Cannot get css or js to load in slim 4

**URL:** <https://discourse.slimframework.com/t/cannot-get-css-or-js-to-load-in-slim-4/4912>\
**Category:** Questions\
**Created:** [August 1, 2021, 2:40am UTC](https://discourse.slimframework.com/t/cannot-get-css-or-js-to-load-in-slim-4/4912 "2021-08-01T02:40:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![meazy](https://avatars.discourse-cdn.com/v4/letter/m/f0a364/32.png) [@meazy](https://discourse.slimframework.com/u/meazy)\
**Post date:** [August 1, 2021, 2:40am UTC](https://discourse.slimframework.com/t/cannot-get-css-or-js-to-load-in-slim-4/4912/1 "2021-08-01T02:40:32Z")

</div>

I am using Odans slim-4-skeleton-master, but instead of php-view I am using Twig. I followed his tutorial on loading twig and everything works except retrieving css or js from public folder. I am not using assets or webpack, just css and js inside the public folder. When I dump {{ url\_for(‘login’) }} I get ‘/’. When I dump {{ base\_path() }} ,{{ base\_path }}, or {{ base\_url }} i get nothing. The error in dev tools is this `http://localhost:8081/css/login.css net::ERR_ABORTED 500 (Internal Server Error)`. I cannot figure out how to get to my css or js. I’ve been trying all kinds of things all day. I am curious how to get ` <link rel="stylesheet" type="text/css" href="{{ base_path }}/css/login.css">` to work. I am also using selective/basepath. I’m not sure if that has anything to do with it.

---

<div class="post-metadata">

**Author:** ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)\
**Post date:** [August 1, 2021, 8:43am UTC](https://discourse.slimframework.com/t/cannot-get-css-or-js-to-load-in-slim-4/4912/2 "2021-08-01T08:43:54Z")

</div>

Hi @meazy

Please take a look at the [documentation of the Slim/Twig](https://github.com/slimphp/Twig-View#custom-template-functions) package. The `base_path()` is a Twig function that returns the Slim application basePath. When you set the basePath with `$app->setBasePath('/sub-dir')';` then `base_path()` should return `/sub-dir`. The `selective/basepath` just detects the sub-directory (if any) and passes the detected basePath to the Slim $app instance automatically.

If `{{ base_path() }}` returns nothing, then you (possibly) already run your application directly in the DocumentRoot of your web server. Please note that the selective/basepath middleware only really supports Apache and the PHP internal web server. Other web servers like nginx may not work correctly because PHP-FPM works differently.

For a quick troubleshooting, I provide a [Slim framework Server Configuration Checker](https://github.com/odan/slim-checker) script that gives you more details about the configuration. It would be nice if you could post the result here.

---

<div class="post-metadata">

**Author:** ![meazy](https://avatars.discourse-cdn.com/v4/letter/m/f0a364/32.png) [@meazy](https://discourse.slimframework.com/u/meazy)\
**Post date:** [August 1, 2021, 12:25pm UTC](https://discourse.slimframework.com/t/cannot-get-css-or-js-to-load-in-slim-4/4912/3 "2021-08-01T12:25:20Z")

</div>

I am running on a the php built in server. I have always done php -S localhost:8080 -t public public/index.php. For slim 4 i have to cd into the public directory and do php -S localhost:8888. I didn’t change anything else. So now I’m wondering, will this break when i put it on a real server? Is there a cloud service that has a slim container to test in? Like Symfony cloud.

---

<div class="post-metadata">

**Author:** ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)\
**Post date:** [August 1, 2021, 1:11pm UTC](https://discourse.slimframework.com/t/cannot-get-css-or-js-to-load-in-slim-4/4912/4 "2021-08-01T13:11:00Z")

</div>

> [@meazy](#):
>
> I am running on a the php built in server.

Ok, then you should not have any problems with the basePath, because your DocumentRoot points already to the public/ directory. On a production server, this should also be configured in the same way.

> Is there a cloud service that has a slim container to test in? Like Symfony cloud.

No, as far as I know. You can still deploy to your QA or staging server and see if everything is configured correctly.
