Search code examples
opencartopencart-3opencart-module

Opencart 3: how to insert to any page data from own module?


I have own module with several fields. I want to show this data in contact page and in the header. How to connect this module for exemple to contact page controller?

I have tried connect it like this:

$data['mymodule'] = $this->load->controller('extension/module/mymodule');

But nothing. What I need to do?

PS. My own mudule doesn't have model. Cotroller and language only.


Solution

  • As I thought, it's very easy to do. But I had to figure out exactly how.

    First of all, we need to connect the modules model in the controller. Then connect the module that we need by ID. At the end, according to the standard opencart scheme, we specify variables for outputting data from the array.

    $this->load->model('setting/module');
    $my_variable = $this->model_setting_module->getModule('module id');
    $data['any_variable'] = $my_variable['any_variable'];
    

    In the template

    {{ any_variable }}