VOLT NOT RENDER ON {% BLOCK CONTENT %}

Hierarchical Block conntent nor tender.. Here it is my main layout: app/views/index.volt

my child view in app/views/index/index.volt

and my result is the same main layout without any content...

I have used phalcon devtools to create my initial crud

and I want to use {%block contents%} instead of {{ content() }}, because it reminds me how other frameworks can override part of the main layout(not all)...



16.8k

Mariano, la próxima vez usa bloques de código (seguramente los desconozcas, es la tilde a la derecha de la P tres veces, metes código, y otras tres veces) y te ahorras tiempo e imágenes.

About your fail... I've Volt declaration in the opposite way:

'.volt' => 'Phalcon\Mvc\View\Engine\Volt',
'.phtml' => function($view, $di) use ($config) {
    // Stuff...
}

Also, I don't see that you had declared $config anywhere. If it still fails with that, check its routes. Also check the server's error log.


Sobre tu fallo... yo tengo justamente la declaración de Volt al revés:

'.volt' => 'Phalcon\Mvc\View\Engine\Volt',
'.phtml' => function($view, $di) use ($config) {
    // Cosas...
}

Además, no veo que tengas declarado $config en ninguna parte. Si aun así falla, revisa las rutas que contiene. Comprueba también el log de errores del servidor.

<?php

return new \Phalcon\Config(array(
    'database' => array(
        'adapter'     => 'Mysql',
        'host'        => 'localhost',
        'username'    => 'root',
        'password'    => '',
        'dbname'      => 'volt',
        'charset'     => 'utf8',
    ),
    'application' => array(
        'controllersDir' => __DIR__ . '/../../app/controllers/',
        'modelsDir'      => __DIR__ . '/../../app/models/',
        'viewsDir'       => __DIR__ . '/../../app/views/',
        'pluginsDir'     => __DIR__ . '/../../app/plugins/',
        'libraryDir'     => __DIR__ . '/../../app/library/',
        'cacheDir'       => __DIR__ . '/../../app/cache/',
        'baseUri'        => '/volt/',
    )
));

This is my config.php file, the app works fine using {{ content() }} but it doesn't work using block contents...I have used phalcon devtools to create the skeleton... I really appriciate your help, I will continue trying to make this work...



16.8k
edited Jan '15

Never show the username and password of a DB.

  1. Try replacing $di->set("view", function(..) {..}, true) to $di->set("view", function(..) {..}).
  2. Check that the route of __DIR__ . "/../../app/views/" is relatively correctly starting from your public folder (or whenever you have your index.php).

I cannot tell much more, because I haven't used devtools yet.

Put {{ content() }} into block content in views/index.volt

{% block content %}
    {{ content() }}
{% endblock %}

like this and test.

I think nested blocks are really a requirement if you want to support template inheritance.

Template inheritance is extremely useful when maintaining front ends, keeps your front-end DRY and also makes it a breeze to keep your front end code organized. But without nested blocks you can effectively only maintain two layers of inheritance.

Thumbs up for nested blocks!

thank you all for your support, I finally achieved

In my main layout (index.volt), I did something like this:

<div class="container-fluid">
           {{ content() }}


       {{ flash.output() }}

       {% block content%}
       {% endblock %}

        {% block content2 %}
       {% endblock %}
    </div>

and then in my layout folders, I've got something like this (in my "sucursal.volt" layout):

{% extends "index.volt" %}

{% block content %}

{% endblock %}

{% block content2 %}
{% endblock %}

and finally in my sucursales folder, I have mi index.volt; something like this:

{% extends 'layouts/sucursales.volt' %}

{% block content %}

{{ super() }}

<div align="right">
    <?php echo $this->tag->linkTo(array("sucursales/new", "Create sucursales")) ?>
</div>
<div align="center">
    <h1>Sucursales</h1>
</div> 

<table id="example23" class="display" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>Sucursal</th>
                <th>Direcci&oacute;n</th>
                <th>Estado</th>
                <th>Modificado</th>
                <th>Modificado por</th>
                <th>Acciones</th>
            </tr>
        </thead>

        <tfoot>
            <tr>
                <th>Sucursal</th>
                <th>Direcci&oacute;n</th>
                <th>Estado</th>
                <th>Modificado</th>
                <th>Modificado por</th>
                <th>Acciones</th>
            </tr>
        </tfoot>
    </table>

    <script>
        $(document).ready(function() {
            $('#example23').dataTable( {
                bProcessing: true,
                "order": [[ 3, "desc" ]],
                sAjaxSource:"/volt/sucursales/get/"
            } );
        } );
    </script>
{% endblock %}