multi module shared views (dual location)

Hi has anything been done in terms of what is asked in this SO question [http://stackoverflow.com/questions/12951048/how-do-i-use-main-layout-views-in-a-multi-module-phalcon-application]?

I was trying to implement this in my project and ended up writing my own code skipping almost all the goodies that phalcon brings to the table. So I scrapped that and I'm asking here as I could not find anything in the docs and the question has been asked quite some time ago. Anyway,

Does phalcon support dual views location?

Thanks, Mike



81.2k

hi Mike, try any of these file structures:

https://github.com/phalcon/mvc/tree/master/multiple-shared-layouts - Use a shared common layout for all modules https://github.com/phalcon/mvc/tree/master/multiple-shared-views - Use the same views directory in both modules

This certainly answers the question, thanks. However I've been looking for something slightly different (I will blame that on the late hour of posting the first question).

What I'm looking to do is to have multiple modules with their own view folder and then have a common folder (let's say "skin"), where I could create overriding templates. This either seems impossible to do at present with phalcon full stack or I simply aproach this wrong.

Here is a structure I'm looking for: ```php |-- app | |-- module1 | |-- view | |-- tpl1.volt | |-- skin | |-- name | |--module1 | |-- tpl1.volt ```

In this scenario we would first check in the skin folder and if template is not there we would fallback to the app/module1/view. I am still working on this (I cannot render anything at the moment), but I thought maybe there is something that I have missed and what would make it a "walk in the park".

Thanks, Mike

I achieved this by extending the Volt Engine. Though this is not a module solution - it might help.

class Skin extends \Phalcon\Mvc\View\Engine\Volt
{
    public function render($path, $params, $mustClean = NULL)
    {
        $skin_template = SKIN_PATH.str_replace(CORE_PATH, NULL, $path);
        if (file_exists($skin_template)) $path = $skin_template;

        return parent::render($path, $params, $mustClean);
    }
}

Obviously setup you own PATH vars somehow, and then register this as the View engine.

Please take a look at this phalcon framework update. It provides support for multiple view packages per website (you can have multiple websites). Users of the magento framework will find it easy to use:

https://github.com/alanbarber111/cloud-phalcon-skeleton