Mixing layout and modules

edited July 2011 in Modules
Hi,

Say I want to create a page that is fully editable through the CMS. In the body of the page, it will have some text, then say, a javascript image carousel, then some more text.

This is how I've done it:

I create a module for the carousel so that the images can be uploaded and changed through the module section in the CMS. Then, in order to make the text customisable through the CMS, I have built a layout for this page that takes the following format:

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

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

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

So, then, by creating the page in the CMS using my new layout, I have the module included, plus the text edited via the CMS and added to the page via tha 'body' variable.

My question is, how would I do this, but add two portions of text, one either side of the carousel module? Is it possible? For example, I'm looking for something like this:

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

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

<?php $this->load->view('carousel')?>

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

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

So, the carousel can be edited via the module in the CMS, and the two portions of text, body1 and body2, can be edited using the page edit in the CMS.

And if the way I've done this is a complete hack, then any advice on the proper way would be appreciated!!

Cheers,
Tallowman

Comments

  • edited 3:08PM
    You can create a new layout that has "body1" and "body2" layout variables in them. The only issue I see is that "body" by default is the field used for uploading the main content of a page (e.g. uploading a view file maps the view data to that field). So perhaps keep "body" and just have a "body2".

    To add to your layout, go to fuel/application/config/My_fuel_layouts.php and add either a new set of layout fields or modify the main layout fields already there. The 'main' key to the layout_fields array maps to the name of the layout in the fuel/applicaiton/views/_layouts folder. You could create a new layout file, say "carousel" and do something like the following:
    $config['layout_fields']['carousel'] = array( 'copy' => array('copy' => lang('layout_field_main_copy')), 'page_title' => array('label' => lang('layout_field_page_title')), 'meta_description' => array('label' => lang('layout_field_meta_description')), 'meta_keywords' => array('label' => lang('layout_field_meta_keywords')), 'body' => array('label' => lang('layout_field_body'), 'type' => 'textarea', 'description' => lang('layout_field_body_description')), 'body2' => array('label' => lang('layout_field_body'), 'type' => 'textarea'), 'body_class' => array('label' => lang('layout_field_body_class')), );
  • edited 3:08PM
    Well, thank you, that worked like a charm :-)

    Fuel is the first CMS I've used, and getting to grips with it slowly, but really like what I see so far. Thanks for all the hard work!
Sign In or Register to comment.