简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM