Is it possible to use the main application layout when rendering module views?

edited June 2014 in Share
Is it possible for view files of a module (located at "/modules/myModule/views/myView.php") to be rendered using layouts defined in "/application/views/_layout"? Or should I create another _layout directory under "/modules/myModule/views"?

This is how I render a module view from its controller under "/modules/myModule/controllers":
$this->fuel->pages->render('myView', $vars, array('view_module' => 'myModule', 'layout' => 'main'));
I tested the above code but the main layout was not found. That's because fuleCMS is apparently looking for the "main" layout in this directory: "/modules/myModule/views/_layout" which does not exist. How can I tell the "render" method where to find the layout file?

Comments

  • edited 12:31AM
    Try creating a "/modules/myModule/views/_layouts/myView.php" folder and then adding "view_module" => 'myModule' in the array of parameters (3rd parameter)
  • edited 12:31AM
    Unfortunately I cannot seem to get it working. It might be too much demanding, but it's very urgent for me to get this to work. Could you please do me a favor and modify the source code of this simple module: http://www.sitepoint.com/getting-started-with-fuel-cms-2/
    and make it render one of their views from one of their controllers, using the default header and footer of fuel cms? I really appreciate any help!
  • edited June 2014
    Ok I could load the module view from its controller using the following method:
    $this->fuel->pages->render('registeration', $vars, array('view_module' => 'registeration'));
    Here is the source code of my view file:
    <?php fuel_set_var('layout', 'main');  echo 'hello';?>
    The main layout is being read and applied from /fuel/application/views/_layouts/main.php:

    <?php $this->load->view('_blocks/header')?>

    <?php echo fuel_var('body', 'This is a default layout. To change this layout go to the fuel/application/views/_layouts/main.php file.'); ?>

    <?php $this->load->view('_blocks/footer')?>
    The HTML of header and footer blocks are loaded, but the "css" and "js" fuel functions in header and footer blocks are not recognized and I get these errors:



    Severity: Notice
    Message: Undefined variable: css
    Filename: core/Loader.php(332) : eval()'d code
    Line Number: 39

    A PHP Error was encountered
    Severity: Notice
    Message: Undefined variable: css
    Filename: core/Loader.php(332) : eval()'d code
    Line Number: 40

    ...

    A PHP Error was encountered
    Severity: Notice
    Message: Undefined variable: js
    Filename: core/Loader.php(332) : eval()'d code
    Line Number: 25

    ...

    How can I get this fixed?
  • edited 12:31AM
    The reason the css and js functions where undefined was:
    In my controller class, I was inheriting from CI_Controller instead of Fuel_base_controller.
Sign In or Register to comment.