0

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?

apokryfos
  • 38,771
  • 9
  • 70
  • 114

1 Answers1

1

Note: This was asked on the official Phalcon forums. I answered it over there and it got accepted. I am just mirroring my answer so future readers can get an answer here without being redirected from StackOverflow. Phalcon forum mirror: https://forum.phalconphp.com/discussion/15891/perform-merge-between-views-of-two-or-more-modules


config.php

You will need to define your modules in the app/config/config.php file like so;

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

*Controller.php

Then, in your controller, you'd set a view property to store the active modules like so;

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

*.volt

And finally in your volt file, just check the module is in the array holding active modules, and if so, display the view using partials.

{% if module01 in modules_enabled %}
   <div id="module">{{ partial("partials/module01") }}</div>
{% endif %}
ʰᵈˑ
  • 11,279
  • 3
  • 26
  • 49