Layouts in Modules?

edited February 2014 in Modules
Hi there,

I'm creating a user module and I have controller "user.php" which has the following function:
_____________________________________________________________

function register() {
$data['foo'] = 'bar';
$this->load->view('register', $data);
}

_____________________________________________________________

Then I have the register.php in /views/ which is:
_____________________________________________________________

<?php
fuel_set_var('layout', 'main');
?>
Register Now:


_____________________________________________________________

Lastly I have main.php in /views/_layouts/:
_____________________________________________________________

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


<?php echo fuel_var('body', ''); ?>


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

Register.php loads, however my layout never does, what am I doing wrong/overlooking?

Comments

  • edited 2:35PM
    To load the layouts, you have to use the Fuel_pages object like so:
    $this->fuel->pages->render('register', $data);

    More on using a controller to display your page content from the CMS can be found here:
    http://docs.getfuelcms.com/general/pages-variables#controller
  • edited February 2014
    Thanks for the speedy reply however this just renders a blank page for me? :(

    Just to clarify the view is a static php file thats just trying to load the layout.
  • edited 2:35PM
    The "register" view file should just include the contents of what you want to appear in the "body" variable. The controller is simply just loading the view file "render" and doesn't know anything about the "main" layout. Using the code specified above will load the "register" view file into the "body" area of the main layout. If there is both a view file and a page created in the CMS of with the location value of "register", you may want to explicitly tell it which to use (either 'views' or 'cms') by using the 'render_mode' property in the third parameter like so:
    $this->fuel->pages->render('register', $data, array('render_mode' => 'views'));
Sign In or Register to comment.