Search code examples
magentoblock

Declare two custom blocks.


I know that in order to create a new custom block we have to add this part to the config.xml file:

<blocks>
        <products1>
            <class>Company_Namespace_Block</class>
        </products1>
</blocks>

This goes for creating a single custom block.

But what if I want to create more than one custom blocks. How should I declare them then? Something like this?

<blocks>
        <products1>
            <class>Company_Namespace_Block</class>
        </products1>
        <products2>
            <class>Company_Namespace_Block</class>
        </products2>
</blocks>

Solution

  • <blocks>
            <products1>
                <class>Company_Namespace_Block</class>
            </products1>
    </blocks>
    

    The above is:

    • Namespace for all of your Module's block classes.
    • Area where all of your block classes will reside.
      (app/code/{codePool}/Company/Namespace/Block).
    • A sort of Prefix for all Block classes of your module (like
      Company_Namespace_Block_Test, Company_Namespace_Block_Test2)

    So, you don't need to replicate the block configuration, to declare more than one block classes. You can declare as many block classes under (app/code/{codePool}/Company/Namespace/Block).