We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Perform merge between views of two or more modules

I have a Phalcon PHP modular application. I am making an administrative interface to control which modules should be used in the system. One module controls the application's default interface, while the other modules add functionalities.

I have the problem: when another module to enabled, it can add the HTML content to the other interface control module. In this way I would like to merge two or more views. I am using Volt as template engine.

Is this possible in Phalcon?



3.4k

How does the application (currently) know if a module is enabled/disabled?

Through the configuration file config.php, located in the config directory at the root of the application.

return new \Phalcon\Config([
...
    'modules' => [
        'module01',
        'module02',
        ...
        'moduleN',
    ],
...
]);

How does the application (currently) know if a module is enabled/disabled?



3.4k
Accepted
answer
edited Apr '17

Then you'll need to do some logic in your controller (to set a view property) and in your view to check the module is enabled. Something like;

*Controller.php

$this->view->modules_enabled = $this->di->get("config")->modules;

*.volt

Then, in your view, something like (assuming the module is in partials/module01);

{% if module01 in modules_enabled %}
   <div id="module">{{ partial("partials/module01") }}</div>
{% endif %}

Hi H!

Thanks for the excellent answer!



3.4k

No worries. Glad to help! :)

Hi H!

Thanks for the excellent answer!