Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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.



8.7k
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);


20.2k

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()?>