Twig-assets in Slim4 route problem


I have follow this page to setup the container

//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.

It will occur 404 not found problem.

Therefore I have a question.
Did the js link should be like this?

If not, what is the correct setting?

Thanks a lot

Hi! It depends on these two settings…

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

$options = [
    // Public assets cache directory
    'path' => '/var/www/',
    // 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.

I have following the settings already.
It still follow the route “/views” like this

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?


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

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


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