We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Using Volt

HI there,

I have the following in my index.php file:

    //Setup the view component
    $di->set('view', function() use ($config) {
        $view = new \Phalcon\Mvc\View();
        $view->setViewsDir(__DIR__ . $config->application->viewsDir);
        $view->registerEngines(array(
            '.volt' => 'volt'
        ));
        return $view;
    });

    $di->set('volt', function($view, $di) {
        $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
        $volt->setOptions(array(
            "compiledPath" => "../cache/volt/"
        ));
        return $volt;
    }, true);

Should I expect Phalcon to still process .phtml files in addition to .volt files or, should I expect Phalcon to process .volt files only?

Many thanks.



15.1k
Accepted
answer

You have to add phtml files as well.

/**
 * Setting up the view component
 */
$di->set('view', function () use ($config) {
    $view = new View();                                                              
    $view->registerEngines(array(
        '.volt' => function ($view, $di) use ($config) {
            $volt = new VoltEngine($view, $di);
            $volt->setOptions(array(
                'compiledPath' => $config->application->cacheDir,
                'compiledSeparator' => '_',
                'compileAlways' => true
            ));
            return $volt;
        },
        '.phtml' => 'Phalcon\Mvc\View\Engine\Php'
    ));

    return $view;
}, true);


38.8k

Excellent. Thanks for this advice :)

Thanks a lot! In this comment I found an answer to my question - "how DISABLE volt in phalcon?" Also, you have to rename index.volt to index.phtml and replace volt's syntax to

<?=$this->getContent()?>