Block data not passed to view

edited June 2011 in Bug Reports
If I want to load a block, without specifying a model, I can pass a data var to the fuel_block method:

echo fuel_block(array('view' => 'test_block', 'data' => array('test' => 'testing var')));

However this array is never passed on to the block your loading, if I'm correct...
If I call '$test' in test_block.php I get 'Undefined variable: test'

Possible fix:
In fuel/modules/fuel/helpers/fuel_helper line 96:

$data = $p['data'];

But $data is never used after that. I think to fix this line 96 should actually be:

$vars = $p['data'];

Because the view (=block) is loaded with the next method on lines 133 / 139:

$view = $CI->load->view("_blocks/".$p['view'], $vars, TRUE);

This way you can call $test in test_block.php.
However there's an extra option 'vars => array()' in the fuel_block() method, which isn't documented.
I'm not exactly sure what it's used for so to be safe, line 96 should be either:

$vars = array_merge($vars, $p['data']);

or:

$vars['data'] = $p['data'];

The latter requires you to call $data['test'] in test_block.php

Please correct me if I'm wrong of course!

Comments

  • edited 2:33AM
    Thanks for the report. I think the idea is to be able to manually pass in model data directly without needing to specify the model in the initialization parameters of the function. Then, that data would be available in a generic variable called "data" to the block. If you specify a model however, that variable data would be available as the variables model short name (e.g. "blocks_model" short name = "blocks"). This is the proposed change:
    $vars['data'] = $p['data'];
  • edited 2:33AM
    Your welcome.
    I think that's the best one too, using it right now and works pretty good.
Sign In or Register to comment.