Nedimo
Nedimo

Reputation: 307

Phalcon View Engines

I am currently using phalcon framework. I want to ask is it possible to use .volt and .phtml file extensions for my views in a same project. In my services.php file view component is set with this code:

$di->set('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 .                      
                                'volt/',
                'compiledSeparator' => '_'
            ));

            return $volt;
        }
    ));

    return $view;
 }, true);

If is possible to write it so it opens .volt view files, as .phtml files, because I need to add some jQuery and Ajax in a view, and i it won't work in .volt.

Thanks in advance.

Upvotes: 0

Views: 528

Answers (1)

twistedxtra
twistedxtra

Reputation: 2699

Yes, you can set up more than one template engine in Phalcon\Mvc\View:

$view->registerEngines(array(
    '.volt' => function($view, $di) use ($config) {

        $volt = new VoltEngine($view, $di);

        $volt->setOptions(array(
            'compiledPath' => $config->application->cacheDir .                      
            'volt/',
            'compiledSeparator' => '_'
        ));

        return $volt;
    },
    '.phtml' => 'Phalcon\Mvc\View\Engine\Php'
));

Upvotes: 1

Related Questions