1

I am trying to include a child block (store_message) within store.phtml. Here is my code:

    <reference name="content">
        <block type="marketplace/store" name="store_list" template="marketplace/storesearch/store.phtml">
            <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
                <block type="page/html_pager" name="product_list_toolbar_pager"/>
                <!-- <action method="setData"><key>_current_grid_mode</key><value>list</value></action> -->
            </block>
            <block type="page/html" name="store_message" template="page/html/store_message.phtml" />       
            <block type="marketplace/store" name="insert_review" template="marketplace/storesearch/insertreview.phtml" />

        </block>
    </reference>

I have read many articles on blocks for magento but still the concept of type=A/B is not very clear to me. If I am going to keep the child block in the same directory as the parent then what is the type=A/B should I give? What is A? What is B?

Some explanations said that A is the class and B is the method. How can a simple child block have a class and method ... its just a template. Can someone please explain?

2

The A is a module's alias. In this case page is short for Mage_Page_Block (it is defined in app/code/core/Mage/Page/etc/config.xml if you want to see).

The B is the class name relative to the alias, initial letters of each word are capitalised. In this case html becomes Html and is appended to the resolved alias, so it is Mage_Page_Block_Html. This is probably found in the file app/code/core/Mage/Page/Block/Html.php because class names translate directly to locations in Magento.

By this, when you would like to have your own custom methods, it allows you to place those there and to be called in your phtml file. In another word, you can call any methods from that block B in that template file.

So any custom method you write, should reside in your block.

If you have block like this:

NameSpace_ModuleName_Block_Myblock and defined as below in your config.xml:

<blocks>
        <modulename>
            <class>NameSpace_ModuleName_Block</class>
        </modulename>
</blocks>

means your type will be modulename/myblock (a/b).

Hope this makes it clear.

More info.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.