Home > Article > Backend Development > Volt engine does not work in phalcon
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
<code>$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; });</code>
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
<code>{{ partial("partials/header") }} {{ partial("partials/main") }} {{ partial("partials/footer") }}</code>
Load js
<code>{{ javascript_include("/js/1.11.3.jquery.min.js") }}</code>
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
<code>$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; });</code>
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
<code>{{ partial("partials/header") }} {{ partial("partials/main") }} {{ partial("partials/footer") }}</code>
Load js
<code>{{ javascript_include("/js/1.11.3.jquery.min.js") }}</code>
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
<code>$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);</code>
Directory structure
The following is part of the code in config/services.php, which is automatically generated when generating the project
<code>$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; });</code>
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
<code>{{ partial("partials/header") }} {{ partial("partials/main") }} {{ partial("partials/footer") }}</code>
Load js
<code>{{ javascript_include("/js/1.11.3.jquery.min.js") }}</code>