Example of extension with listing block
Extension with listing block wrapper (appearance controller)
1. Load custom listing block settings to the layout. Best way to do this is via XML load.
2. Add a hook into your extension on ControllerPagesDesignBlocks (Control Panel side). This will add controller(wrapper) to selection in control panel and show listing on storefront using your templates.
public function onControllerPagesDesignBlocks_InitData() { $this->baseObject->data[ 'block_wrappers' ]['blocks/extension_listing_controller'] = '[extension_name]'; }
3. In main.php file of your extension add list of templates which will be used in list view. Number of templates depends on your block listing extensions controller.
$templates = array( 'storefront' => array('blocks/some-template-name1.tpl', 'blocks/some-template-name2.tpl', 'blocks/some-template-name3.tpl', 'blocks/some-template-name4.tpl',....));
4. Place above template files into folder ยซ[extension_name]/storefront/view/default/templates/blocks/ยป ย
5. Create listing block controller file in ยซ[extension_name]/storefront/controller/blocksยป
<?php if (! defined ( 'DIR_CORE' )) { header ( 'Location: static_pages/' ); } class ControllerBlocksExtensionName extends AController { public $data; public function main() { //init controller data $this->extensions->hk_InitData($this); $block_data = func_get_args(1); $parent_block_txt_id = $block_data[0]; $block_data = $block_data[1]; if($block_data){ $this->view->assign('content',$block_data['content']); $this->view->assign('heading_title', $block_data['title'] ); switch($parent_block_txt_id){ case 'content_top': $template = ''blocks/some-template-name1.tpl''; break; case 'column_left': $template = ''blocks/some-template-name3.tpl''; break; case 'column_right': $template = ''blocks/some-template-name4.tpl''; break; default: $template = ''blocks/some-template-name2.tpl''; break; } $this->processTemplate( $template ); } } } ?>
6. Add your controller into main.php to $controllers array:
$controllers = array( 'storefront' => array('blocks/[extension_name]' ));