Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How can I call a partial from another module?
  • I would like to call a partial which I have in the Main Module also in the Users Module?

    I don't understand really the user of \Theme::instance()->use_modules()->set_partial.

    Is that the correct way to do that?

    I tried the following:
    #\Theme::instance()->set_partial('subnavigation', 'admin/partials/settings_subnavigation');
    \Theme::instance()->set_info('use_module', 'main', 'active');
    \Theme::instance()->use_modules()->set_partial('subnavigation', 'admin/partials/settings_subnavigation')->use_modules(true);



    Thanks
    Kay
  • The correct way of doing that is through HMVC.

    Have your user module call a controller method in your main method using Request::forge(), and have that method return the required view.  Alternatively you can pass the theme instance to the request, and have the method call set_partial() on it so it doesn't have to return the view.

    This will produce the correct level of abstraction between your modules. You should put that request in a try/catch block, so make sure that Request doesn't produce a 404 for some reason.

    If you want the Quick and Dirtry approach, you can also pass a View object to set_partial(), instead of a string containing a view path. You can directly load a view from another module by prefixing the view path:
    \Theme::instance()->set_partial('subnavigation', \View::forge('othermodule::this/view/file'));
    Since this creates tight coupling between the two modules (because of the hardcoded name in your code), it is frowned upon. But it's your code, so you can use it if you want.
  • When I do

    \Theme::instance()->set_partial('subnavigation', \View::forge('Main::admin/partials/settings_subnavigation'));


    then I still get an error message:
    The requested view could not be found: Main::admin/partials/settings_subnavigation

    How do I have to call the view correctly?
  • HarroHarro
    Accepted Answer
    Not sure you can have underscores in view filenames. You can't for all other files.

    And your Main module must be loaded for this to work, otherwise the module path is not known to the finder and the view will not be found.
  • Thanks Harro,
    that was it. :-)

    I now have:
    \Module::load('main');
    \Theme::instance()->set_partial('subnavigation', \View::forge('main::admin/partials/settingssubnavigation'));

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion