How to display the module in a block

edited February 2018 in Modules
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)) :
redirect_404();
endif;

else:

$cheeses = fuel_model('cheeses');

endif;

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

<?=fuel_edit($cheese)?><?=$cheese->cheese_name?>


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


<?php else: ?>

Cheeses

<?=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?

Comments

  • edited 2:57PM
    Try this instead:
    <?php echo fuel_block('cheeses/our_cheeses'); ?>
  • edited 2:57PM
    Ah, you're a star, thank you!
  • edited 2:57PM
    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.
  • edited 2:57PM
    Hi ale_sasu,

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