E_p E_p - 2 years ago 115
PHP Question

Have problems with using Volt with phalcon

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.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();
".html" => 'volt'
$view->render("index", 'index');
echo $view->getContent();


{% extends "layouts/main.html" %}
{% block content %}
{% endblock %}


{% 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'

Answer Source

That comes from the fact that the application cannot find the file main.html in the actual path. If you add the full path it works, however it is inconvenient to do so.

Something like this will work

{% extends  "../views/layouts/main.html" %}

or if your app is under app

{% extends  "../app/views/layouts/main.html" %}

I 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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download