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

How can you set the compile path for a simple view?

Hi I have a module view for a CMS I am writing and for the individual modules, I am using simple view, however due to the method of deployment, the view folder is not writable, I use a folder outside the main path to put anything writable in, so my question is how can I set the ccompile path with simple view? See my code below:

$di->set('moduleView', function() use ($config) {
    $simpleView = new Phalcon\Mvc\View\Simple();
    $simpleView->setViewsDir('../modules/NewInToday/Frontend/Views/');
    $simpleView->registerEngines(array(".volt" => "Phalcon\Mvc\View\Engine\Volt"));
    return $simpleView;
}, true);


4.0k
Accepted
answer

Setting up the Volt Engine

$di->set('voltService', function($view, $di) {
    $volt = new Volt($view, $di);
    $volt->setOptions(array(
        "compiledPath" => "../app/compiled-templates/",
        "compiledExtension" => ".compiled"
    ));
    return $volt;
});

$di->set('moduleView', function() use ($config) {
    $simpleView = new Phalcon\Mvc\View\Simple();
    $simpleView->setViewsDir('../modules/NewInToday/Frontend/Views/');
    $simpleView->registerEngines(array(".volt" => "voltService"));
    return $simpleView;
}, true);

Cheers!

Setting up the Volt Engine

$di->set('voltService', function($view, $di) {
   $volt = new Volt($view, $di);
   $volt->setOptions(array(
       "compiledPath" => "../app/compiled-templates/",
       "compiledExtension" => ".compiled"
   ));
   return $volt;
});

$di->set('moduleView', function() use ($config) {
   $simpleView = new Phalcon\Mvc\View\Simple();
   $simpleView->setViewsDir('../modules/NewInToday/Frontend/Views/');
   $simpleView->registerEngines(array(".volt" => "voltService"));
   return $simpleView;
}, true);