Seams that inheritance does not work in volt templates.
Phalcon version is 0.6.1
Have a file structure:
- views/
- index/
- index.html
- layouts/
- main.html
- index/
- index.php
index.php:
<?php
$di = new Phalcon\DI\FactoryDefault();
$di->set('volt', function ($view, $di){
return new Phalcon\Mvc\View\Engine\Volt($view, $di);
});
$view = new \Phalcon\Mvc\View();
$view->setViewsDir("views/");
$view->registerEngines(array(
".html" => 'volt'
));
$view->setDi($di);
$view->start();
$view->render("index", 'index');
$view->finish();
echo $view->getContent();
views/index/index.html
{% extends "layouts/main.html" %}
{% block content %}
<h2>Index</h2>
{% endblock %}
views/layout/main.html
<h1>Main</h1>
{% block content %}
Not index
{% endblock %}
When I run php index.php I get:
Uncaught exception ‘Phalcon\Mvc\View\Exception’ with message ‘Template view to extend ‘layouts/main.html’ doesn’t exists’
That comes from the fact that the application cannot find the file
main.htmlin the actual path. If you add the full path it works, however it is inconvenient to do so.Something like this will work
or if your app is under
appI believe there should be a way to either reference the root path and/or the views path directly from Volt’s setup. That could very well be a NFR.