2

Hi could any one tell

methods used in in layout file and its functionality in magento

for example

<action method=”insert”>
<action method=”setImgSrc”>

can any one list defalut methods used in layout file.

1 Answer 1

14

1.You can use any public methods of block (or it's parent blocks) class in layout, for ex.:

<block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
    <action method="addColumnCountLayoutDepend"><layout>empty</layout><count>6</count></action>
    <action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
</block>

Block class of catalog/product_list is Mage_Catalog_Block_Product_List. And parent class of this block Mage_Catalog_Block_Product_Abstract has method addColumnCountLayoutDepend with two arguments:

//<action method="addColumnCountLayoutDepend">'empty'      '6'
  public function addColumnCountLayoutDepend( $pageLayout, $columnCount)
  {
      $this->_columnCountLayoutDepend[$pageLayout] = $columnCount;
      return $this;
   }

We can dispatch this method using <action method="doSomeMethod"><param1>value</param1><param2>value</param2></action>. By the way this is actual methods of classes.

2.You can set any data to the block using magick getter and setters of Magento Object: setSomeData($value). Because of all blocks of Magento inherits from Varien_Object class:

<block type="core/template" name="left.permanent.callout" template="callouts/left_col.phtml">
    <action method="setImgSrc"><src>images/media/col_left_callout.jpg</src></action>
    <action method="setImgAlt" translate="alt" module="catalog"><alt>Our customer service is available 24/7. Call us at (555) 555-0123.</alt></action>
    <action method="setLinkUrl"><url>checkout/cart</url></action>
</block>

This is same with $block->setImgSrc('images/media/col_left_callout.jpg') and in template file you can use $this->getImgSrc() to retrive already setted data.

3.Dispath methods via reference:

<reference name="footer_links">
    <action method="addLink" translate="label title" module="catalog" ifconfig="catalog/seo/site_map"><label>Site Map</label><url helper="catalog/map/getCategoryUrl" /><title>Site Map</title></action>
</reference>

footer_links block is defined in page.xml layout:

<block type="page/template_links" name="footer_links" as="footer_links" template="page/template/links.phtml"/>

Open block class Mage_Page_Block_Template_Links:

public function addLink($label, $url='', title='', ....)
{
   //....
}

I hope this is helpfull.

2
  • 2
    Nice explanation. I may add that anything that starts with uns is also valid. It will call unsetData.
    – Marius
    Feb 7, 2014 at 6:58
  • 1
    This. Also, if you're interested is browsing the available methods by block type, you ma be interested in my old developer manual extension. magentocommerce.com/magento-connect/developer-manual.html Feb 7, 2014 at 6:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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