Create a new Block in Magento

我的未来我决定 提交于 2019-12-04 18:46:09

There are many different blocks available that you can use without creating your own. In this case I think core/text_list would be suitable because it doesn't require a template and can have as many child blocks within it as you need.

<?xml version="1.0"?>
<layout version="0.1.0"><!-- All layout files start with this -->
    <cms_index_index><!-- Index directive is the same as "home" page -->
        <reference name="root"><!-- For more blocks that can be referenced see "default" directive -->
            <block type="core/text_list" name="home_flash">
                <block type="cms/block" name="home-page-flash">
                    <action method="setBlockId"><block_id>home-page-flash</block_id></action>
                </block>
            </block>
        </reference>
    </cms_index_index>

    <!-- More directives might go here -->

</layout>

Other useful block types worth knowing are core/text and core/template which correspond to Mage_Core_Block_Text and Mage_Core_Block_Template respectively. They get used the most.
Your home made block type of page/html_home_block didn't have any PHP class with a matching name, and if you were genuinely creating your own you wouldn't be able to use the page prefix since Magento already does.

To create a block you only need a <block> tag in the layout file.
To create a block type you need to write a PHP class, give it a namespace and declare it as part of a module.
To add to an existing block is the time when you use a <reference> tag.

There are many fine articles at Magento Knowledge Base including some on Theming & Design.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!