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

How to Force Phalcon to pick view from another module instead of defined?

Currently I am loading all users on URL/Route /admin/config/users which is picking this view ( private/apps/Admin/Views/user/users.volt ) from Admin module.

Now I have set a flag for custom layout. So if custom layout is enabled I want the phalcon to pick view from AdminExtension module i.e ( private/apps/Admin/Extension/Views/user/users.volt )

How can I achive this? I want both views. Because private/apps/Admin/Views/user/users.volt is default view for listing all users. However private/apps/Admin/Extension/Views/user/users.volt is customised view for client where a lot of design changes are done.

Dispatcher code:

    /**
     * @param Dispatcher $dispatcher
     */
    public function afterExecuteRoute(Dispatcher $dispatcher) {

        // Check if Json response is required
        if ($this->_isJsonResponse) {

        } else {

            if(CxSettingCustomLayout::loadFromDb()->isCustomLayout()) {
                //pick custom view here" `private/apps/Admin/Extension/Views/user/users.volt`
            }

            // Build current module configuration settings section name
            $moduleConfigName = 'app_' . $this->dispatcher->getModuleName();
            // Include assets configuration file where assets collections are defined
            if(file_exists($this->config[ $moduleConfigName ]['assetsFile']))
                include $this->config[ $moduleConfigName ]['assetsFile'];

            // Set a view variable with the current language code
            $this->view->setVar('current_language_code', $this->CxTranslation->getLanguage()->getCode());
        }
    }

This seems like the sort of thing that should be done at the action-method level in the controller. You should be able to accomplish this by using $this->view->pick https://docs.phalcon.io/3.4/en/views#picking-views

If this view has a bunch more functionality, it might make sense to consider making a different action method to handle it.