Change index.phtml to index.volt

Hello. I have phalcon 2.0.9. I create new project with help phalcon devtools: phalcon project blog --type=modules. When I try change index.phtml to index.volt (and $this->getContent() to {{ content() }} in file) I have white page. In httpd error log is empty. Who know how I can fixed that? Thanks.

Did you register volt in view as engine ?



1.1k

Yes. Volt automatically register after create project: config/services.php:

$di->setShared('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, 'compiledSeparator' => '_' )); return $volt; }, '.phtml' => 'Phalcon\Mvc\View\Engine\Php' )); return $view; });

So maybe clear cache dir ?



1.1k
edited Dec '15

No. I create new project, change index.phtml to index.volt , "->getContent();" to "{{ content() }}", open site and have white page. If I try in blog/public/index.php

var_dump( $application->handle()->getContent() );

I have:

string(0) ""

A feeling that phalcon ignore volt extension.

Well cuz you are misunderstanding it. getContent() method returns a response with rendered view.

{{ content() }}

Will call a function added to volt compiler which doesnt exist. If you want to add variable to volt you have to:

$this->view->setVar('something','something here');

And then in volt {{ something }} will output in html 'something here'.



1.1k
edited Dec '15

I understand that, but the file also has a connection js file link, but on the page and that there is no. Please try create project:

phalcon project blog --type=modules

and change index.phtml -> index.volt in blog/apps/frontend/views/ and go this page, you work?

Also instead of httpd error check php error/related log error to your vhost. There must be some error. What happens if you delete {{ content() }} ?



1.1k
edited Dec '15

1) I recreated httpd error log file - after refresh page, log file is empty

2) Page still white

The same problem occurs on two computers with different operating systems (Ubuntu and Mac OS X)



1.1k
edited Dec '15

I fixed this. In blog/apps/frontend/Module.php In:

$di['view']

Need add:

$view->registerEngines(array( ".volt" => 'Phalcon\Mvc\View\Engine\Volt' ));

Thanks for this repo manual: https://github.com/phalcon/mvc/blob/master/multiple-volt/apps/frontend/Module.php

Or change $di['view'] to:

$di['view'] = function () use ($config) { $view = new View(); $view->setViewsDir(DIR . '/views/'); $view->registerEngines(array( '.volt' => function ($view, $di) use ($config) { $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di); $volt->setOptions(array( 'compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_' )); return $volt; } )); return $view; };

And add in blog/apps/frontend/config/config.php:

'cacheDir' => DIR . '/../cache/',

For cache compile template.

But I don't understand, why in simple project default use volt but modules used phtml.