Multi Module Shared Layouts

I've searched and played around 3 hours, so it's fair to make a post about this. I am trying to convert to a multiple setup.

So I have something like this of a* directory tree*:

/app
    /dashboard
        /controllers
            IndexController.php
        /models
        /views
            index.volt
        Module.php

1: There a big disconnect for me to use volt views within a Module. Especially Shared Templates. For example, within the app/dashboard/views/index.volt I can extend the main layout very deep via {% extends "../../shared/views/templates/full.volt" %}. Yet if I have another extension within the full.volt it seems nearly impossible to get the path right to include a sub-view no matter how many ../'s I add.

2: I was under the assumption that the Volt library extended the Abstract View library, hence I tried doing: setLayoutsDir() and setTemplateAfter(), but I can't do that. That is another topic, because I can extend in point #1. So I realized I can do the following alternatively to #1:

$di->set('view', function () {
    $view = new \Phalcon\Mvc\View();
    $view->setViewsDir('../app/frontend/views/');

    // Apply to the $view not $volt
    $view->setLayoutsDir('../../shared/views/templates');
    $view->setTemplateAfter('full');

    $view->registerEngines([
        '.volt' => function ($view, $di) {

            // Volt Template Engine
            $volt = new VoltEngine($view, $di);

            $volt->setOptions([
                'compiledPath' => '../../cache',
                'compiledSeparator' => '_',

                // For DEV, to prevent Caching annoyances
                'compileAlways' => true
            ]);

            return $volt;
        },
        // Fallback
        '.phtml' => 'Phalcon\Mvc\View\Engine\Php'
    ]);

    return $view;
});

It would also appear to me that the bootstrap loader->registerDirs() has nothing to do with shared templates.

So I suppose my question is #1 -- How can I extend a template from within a template using volt include

Compliments: This multiple module system is competitive among Symfony2 and Django, and indeed very similar. Yet, Phalcon overpowering in speed and destroying the nuisances of development time in Symfony2 Standard Framework. I do wish there was more documenation and advanced use cases for these multiple modules, I only have the mvc github to go by and the docs I can up.



30.7k

Yet if I have another extension within the full.volt it seems nearly impossible to get the path right to include a sub-view no matter how many ../'s I add.

So I suppose my question is #1 -- How can I extend a template from within a template using volt include

do you mean in full.volt you want {% extends "anotherTemplate.volt" %} ?

do you mean in full.volt you want {% extends "anotherTemplate.volt" %} ?

Yes!



30.7k

Imho, if "anotherTemplate.volt" is in same directory as full.volt, a simple {% extends "anotherTemplate.volt" %} should do the trick.