In the generated multi-module project, the volt engine does not work, js and css loading does not respond, partials does not work, and the view cannot be output. It seems that the volt engine has not been registered successfully or is it due to other reasons?
ps: But it comes with its own engine. Files in the format with the suffix .phtml can import js, css, and partials files according to the manual. Based on the above, after changing the suffix to .volt format, what else needs to be changed to make it work?
Directory structure
The following is part of the code in config/services.php, which is automatically generated when generating the project
$di->setShared('view', function () use ($config) { $view = new View(); $view->setViewsDir($config->application->viewsDir); $view->registerEngines(array( '.volt' => function ($view, $di) use ($config) { $volt = new VoltEngine($view, $di); $volt->setOptions(array( 'compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_' )); return $volt; }, '.phtml' => 'Phalcon\Mvc\View\Engine\Php' // '.volt' => 'Phalcon\Mvc\View\Engine\Php' )); return $view; });
Module.php under the module is still the same as when the project was generated and has not changed!
in views/index.volt
Loading partials
{{ partial("partials/header") }} {{ partial("partials/main") }} {{ partial("partials/footer") }}
Load js
{{ javascript_include("/js/1.11.3.jquery.min.js") }}
In the generated multi-module project, the volt engine does not work, js and css loading does not respond, partials does not work, and the view cannot be output. It seems that the volt engine has not been registered successfully or is it due to other reasons?
ps: But it comes with its own engine. Files in the format with the suffix .phtml can import js, css, and partials files according to the manual. Based on the above, after changing the suffix to .volt format, what else needs to be changed to make it work?
Directory structure
The following is part of the code in config/services.php, which is automatically generated when generating the project
$di->setShared('view', function () use ($config) { $view = new View(); $view->setViewsDir($config->application->viewsDir); $view->registerEngines(array( '.volt' => function ($view, $di) use ($config) { $volt = new VoltEngine($view, $di); $volt->setOptions(array( 'compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_' )); return $volt; }, '.phtml' => 'Phalcon\Mvc\View\Engine\Php' // '.volt' => 'Phalcon\Mvc\View\Engine\Php' )); return $view; });
Module.php under the module is still the same as when the project was generated and has not changed!
in views/index.volt
Loading partials
{{ partial("partials/header") }} {{ partial("partials/main") }} {{ partial("partials/footer") }}
Load js
{{ javascript_include("/js/1.11.3.jquery.min.js") }}
Post the code part for registering your volt template in DI
Post the code part for loading JS and CSS
Post the code part for using partial
Post the code! Post the code! Post the code! Let’s talk about three again! Raising code-related questions without posting the code is a hooligan
$di->set('view', function () use ($config) { $view = new View(); $view->setViewsDir(APP_PATH . $config->application->layouts_dir); $view->registerEngines( array( '.volt' => function ($view, $di) use ($config) { $volt = new VoltExtension($view, $di); $volt->setOptions( array( 'compiledPath' => APP_PATH . $config->application->cache_dir, 'compileAlways' => $config->application->debug, 'compiledSeparator' => '_', 'layoutDir' => $config->application->layouts_dir, )); if (!empty($config->volt->extensions)) { foreach ($config->volt->extensions as $extension_class_name) { $di->get('volt.extension')->register($volt, new $extension_class_name($di)); } } return $volt; }, '.phtml' => 'Phalcon\Mvc\View\Engine\Php' ...... )); return $view; }, true);
Directory structure
The following is part of the code in config/services.php, which is automatically generated when generating the project
$di->setShared('view', function () use ($config) { $view = new View(); $view->setViewsDir($config->application->viewsDir); $view->registerEngines(array( '.volt' => function ($view, $di) use ($config) { $volt = new VoltEngine($view, $di); $volt->setOptions(array( 'compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_' )); return $volt; }, '.phtml' => 'Phalcon\Mvc\View\Engine\Php' // '.volt' => 'Phalcon\Mvc\View\Engine\Php' )); return $view; });
Module.php under the module is still the same as when the project was generated and has not changed!
in views/index.volt
Loading partials
{{ partial("partials/header") }} {{ partial("partials/main") }} {{ partial("partials/footer") }}
Load js
{{ javascript_include("/js/1.11.3.jquery.min.js") }}