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.

up vote 12 down vote accepted

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.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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