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

partial not finding file

I'm trying to include a partial something like this:


mydir/index.volt:

{{ partial('mydir/menu.volt') }}

However, it just gives me a file not found error:

View '../app/views/mydir/menu.volt' was not found in the views directory

I've confirmed that menu.volt is correct, and actually exists in the correct dir. What am I missing that volt is not able to find the file to include?



22.8k

Hi,

Have you set the views directory in your configuration or bootstrap file? For example :

/**
* Setting up the view component
*/
$di->set('view', function () use ($config) {
    $view = new View();
    $view->setViewsDir($config->application->viewsDir); // insert your views dir path here    
    $view->setPartialsDir('partials/');
    $view->registerEngines(array(
        '.phtml' => 'Phalcon\Mvc\View\Engine\Php'
    ));
return $view;
}, true);


14.9k
edited Apr '15

Gah, ok had some caffeine and found my error :) Knew it was a stupid mistake.

partial call doesn't include the file extension. Should be:

{{ partial('mydir/menu') }}