How to find the name in layout of a block in Magento

Lesti_Fpc needs the name_in_layout of a block to make that block lazy or dynamic. Magento needs a unique identitfier for every block in the layout. That is the Name in Layout of a block. You can get this name with the following function.

$blockName = $block->getNameInLayout();

Or you can find the name in the layout.xml of your extensions. For example the app/design/frontend/base/default/layout/checkout.xml.

<!-- ... -->
<block type="checkout/cart_sidebar" name="cart_sidebar" template="checkout/cart/sidebar.phtml" before="-">
<!-- ... -->

The searched attribute is name.

An Example

When I'm searching for the name of a block I start at the frontend. My prefered helper is firebug. In my example, I will search the minicart in the sidebar.

Minicart

Now I know the html of this block a little bit. I'm searching for unique things, that I can find in the template of the block.

<!-- ... -->
<div class="block block-cart">
        <div class="block-title">
        <strong><span>My Cart</span></strong>
    </div>
    <div class="block-content">
                        <p class="empty">You have no items in your shopping cart.</p>
        </div>
</div>
<!-- ... -->

In my example, I will take the class block-cart. I just have to find this little snippet in the code of my shop. I just found one usage of this class in app/design/frontend/base/default/template/checkout/cart/sidebar.phtml.

/** ... */
<?php if ($this->getIsNeedToDisplaySideBar()):?>
<div class="block block-cart">
    <?php $_cartQty = $this->getSummaryCount() ?>
/** ... */

Be sure to take the right template. Now I know the name of the template file and can search in the layout.xml's for this template. I just have to search for checkout/cart/sidebar.phtml. I did find it twice.

app/design/frontend/base/default/layout/checkout.xml
<!-- ... -->
<block type="checkout/cart_sidebar" name="cart_sidebar" template="checkout/cart/sidebar.phtml" before="-">
<!-- ... -->
app/design/frontend/base/default/layout/customer.xml
<!-- ... -->
<block type="checkout/cart_sidebar" name="cart_sidebar" template="checkout/cart/sidebar.phtml">
<!-- ... -->

Now I know the name of my block, cart_sidebar. Please note, it's recommended to place blocks over an layout.xml to the layout, but not every block is defined like that. A developer could also set the template over setTemplate function in the php-file. You may also have to search in the codepool for the name of a block. But taht's uncommon.

If you have the name of the block you can add it to the lazy or dynamic blocks in the configuration of Lesti_Fpc.

Next Previous