# Twig-assets in Slim4 route problem

**URL:** https://discourse.slimframework.com/t/twig-assets-in-slim4-route-problem/4396
**Category:** Questions
**Created:** [September 11, 2020, 12:46pm UTC](https://discourse.slimframework.com/t/twig-assets-in-slim4-route-problem/4396 "2020-09-11T12:46:26Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![fungfungsm](https://avatars.discourse-cdn.com/v4/letter/f/839c29/32.png) [@fungfungsm](https://discourse.slimframework.com/u/fungfungsm)
#### Post date: [September 11, 2020, 12:46pm UTC](https://discourse.slimframework.com/t/twig-assets-in-slim4-route-problem/4396/1 "2020-09-11T12:46:26Z")

</div>

Hello,

I have follow this page to setup the container  
[twig-assets](https://github.com/odan/twig-assets)

> //Path settings  
> $settings[‘root’] = dirname( **DIR** );  
> $settings[‘temp’] = $settings[‘root’] . ‘/tmp’;  
> $settings[‘public’] = $settings[‘root’] . ‘/public’;

However, the created twig with js/css (test.js) in a route “/views”.  
Then this is the js link.  
[http://127.0.0.1:8888/views/cache/test.xxx.js](http://127.0.0.1:8888/views/cache/test.xxx.js)

It will occur 404 not found problem.

Therefore I have a question.  
Did the js link should be like this?  
[http://127.0.0.1:8888/cache/test.xxx.js](http://127.0.0.1:8888/cache/test.xxx.js)

If not, what is the correct setting?

Thanks a lot

---

<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: [September 11, 2020, 4:25pm UTC](https://discourse.slimframework.com/t/twig-assets-in-slim4-route-problem/4396/2 "2020-09-11T16:25:57Z")

</div>

Hi! It depends on these two settings…

All compiled assets (js,css) will be copied into the `path` directory.

```php
$options = [
    // Public assets cache directory
    'path' => '/var/www/example.com/htdocs/public/assets/cache',
        
    // The public url base path
    'url_base_path' => 'assets/cache/',

```

The `url_base_path` represents the public path of the url to that directory.  
Make sure that the `url_base_path` refers to the `path` of the physical directory.

---

<div class="post-metadata">

### Author: ![fungfungsm](https://avatars.discourse-cdn.com/v4/letter/f/839c29/32.png) [@fungfungsm](https://discourse.slimframework.com/u/fungfungsm)
#### Post date: [September 14, 2020, 2:21am UTC](https://discourse.slimframework.com/t/twig-assets-in-slim4-route-problem/4396/3 "2020-09-14T02:21:01Z")

</div>

Hi!  
I have following the settings already.  
It still follow the route “/views” like this  
[http://127.0.0.1:8888/views/cache/file.xxx.js](http://127.0.0.1:8888/views/cache/file.xxx.js)

Still occur 404 not found problem.

```
// Path settings
$settings['root'] = dirname( __DIR__ );
$settings['temp'] = $settings['root'] . '/tmp';
$settings['public'] = $settings['root'] . '/public';

$settings['assets'] = [
// Public assets cache directory
'path' => $settings['public'] . '/assets/cache',
'url_base_path' => 'assets/cache/',
// Cache settings
'cache_enabled' => true,
'cache_path' => $settings['temp'],
 'cache_name' => 'assets-cache',
// Should be set to 1 (enabled) in production
'minify' => 0,
];

```

Should I follow the route to change the assets’ path?

Thanks

---

<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: [September 14, 2020, 9:59am UTC](https://discourse.slimframework.com/t/twig-assets-in-slim4-route-problem/4396/4 "2020-09-14T09:59:20Z")

</div>

I think in your case the settings should look like this, but I’m not sure.

```php
$options = [
    'path' => $settings['public'] . '/views/cache',
    'url_base_path' => 'views/cache/',
    // ...

```

---

<div class="post-metadata">

### Author: ![fungfungsm](https://avatars.discourse-cdn.com/v4/letter/f/839c29/32.png) [@fungfungsm](https://discourse.slimframework.com/u/fungfungsm)
#### Post date: [September 15, 2020, 2:04am UTC](https://discourse.slimframework.com/t/twig-assets-in-slim4-route-problem/4396/5 "2020-09-15T02:04:10Z")

</div>

Hi!

Thanks for your support!  
I have fixed the problem with your solution.
