How to display the module in a block
  • Hello,

    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) : ?>

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



    <?php endforeach; ?>

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

    What am I missing?
  • Try this instead:
    <?php echo fuel_block('cheeses/our_cheeses'); ?>
  • Ah, you're a star, thank you!
  • Hello.

    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.
  • Hi ale_sasu,

    I guess you would use this: $cheeses = fuel_model('cheeses');

Howdy, Stranger!

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