Twig-assets in Slim4 route problem

Hello,

I have follow this page to setup the container
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

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

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

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

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

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

Hi!

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