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.

Volt compile path not change

Hello, i do this in the public/index.php file in order to set var/compiled_templates as Volt compliedPath attribute, but Volt still using views directory as default, what is the problem ? the var directory is in the root path of the app and have the same level as public directory.

    $di->set("voltService", function($view, $di) {
        $volt = new Volt($view, $di);
        $volt->setOptions(array(
            "compiledPath" => "../var/compiled_templates/",
            "compiledExtension" => ".compiled"
        ));

        return $volt;
    });

    // inject View service to the dependeny container
    $di->set('view', function() use ($config){
        $view = new Phalcon\Mvc\View();
        $view->setViewsDir($config->application->views_dir);
        $view->registerEngines(
            array(
                ".volt" => "Phalcon\Mvc\View\Engine\Volt"
            )
        );
        return $view;
    });

I'm guessing your path isn't correct. Echo the compiledPath option after you've set it to see what Volt actually thinks it is. Just as an experiment, set compiledPath as an absolute path (rather than a relative one) to see if it works. Perhapse since you've used a relative path, the directory from which that path is relative might be different than you expect.



9.6k

Okay, I put die statment on the volt service definition section but noting happen, i guess whole of this section are ingnored ... i have syntax error ?

Looking at it again, the problem may be with how you're declaring your Volt service. I don't know if this matters, but I have Volt set up in my bootstrap, from inside the declaration to set the view:

$DI->set('view',function() use($Config){
    $View = new \Phalcon\Mvc\View();
    $View->setViewsDir($Config->dir->views_dir);
    $View->registerEngines(['.phtml'=> function($View,$DI) use ($Config){
                                        $Volt = new \Phalcon\Mvc\View\Engine\Volt($View,$DI);
                                        $Volt->setOptions([  'compiledPath'        =>   $Config->dir->views_compile_dir,
                                                            'compileAlways'       =>   $Config->app->views_compile_always,
                                                            'compiledSeparator' => '::'
                                                          ]);
                                        $Compiler = $Volt->getCompiler();
                                        $Compiler->addFunction('strtotime','strtotime');
                                        $Compiler->addFunction('number_format','number_format');
                                        return $Volt;
                                    }
                        ]);
    return $View;
});


9.6k
Accepted
answer

Okay, i find the problem, in the $view->registerEngines i must passes the "voltService" instead of Phalcon\Mvc\View\Engine\Volt.

Thank you quasipickle