How to display the module in a block

edited February 2018 in Modules

I am following your simple modules tutorial.

I need to create a block that displays a list of cheeses from the cheeses table on the home page.

In MY_fuel_modules I added:

$config['modules']['cheeses'] = array(
'preview_path' => 'cheeses/{slug}',
'display_field' => 'cheese_name',
'sanitize_input' => array('template','php'),
// 'view_location' => Not sure what to put here...

On views/_layouts/main.php I added:

<?php echo fuel_block('our_cheeses'); ?>
I created this block: views/_blocks/cheese/our_cheeses.php

The code:

$slug = uri_segment(2);

if ($slug):
$cheese = fuel_model('cheeses', array('find' => 'one', 'where' => array('slug' => $slug)));

if (empty($cheese)) :


$cheeses = fuel_model('cheeses');


if (!empty($cheese)) : ?>


imageimage_path?>" alt="<?=$cheese->title_entities?>" class="img_right">

<?php else: ?>


<?=fuel_edit('create', 'Create Cheese', 'cheeses')?>

Our Cheese

<?php foreach($cheeses as $cheese) : ?>

<?php endforeach; ?>

But when I go to the home page, the block does not display.

What am I missing?


  • edited 8:14PM
    Try this instead:
    <?php echo fuel_block('cheeses/our_cheeses'); ?>
  • edited 8:14PM
    Ah, you're a star, thank you!
  • edited 8:14PM

    I have a question. What happen when you want more than one result? I reffered to this line:

    $cheese = fuel_model('cheeses', array('find' => 'one', 'where' => array('slug' => $slug)));

    How i can change the code to obtain more than one data? Thanks a lot.
  • edited 8:14PM
    Hi ale_sasu,

    I guess you would use this: $cheeses = fuel_model('cheeses');
Sign In or Register to comment.