Magento - Is it possible to specify multiple values for ifconfig?

3.6k views Asked by At

I want to specify multiple values for ifconfig in layout xml.

<action method="setTemplate" ifconfig="mymodule/general/is_enabled">
    <template>mymodule/test.phtml</template>
</action>

Is is possible to add below two conditions for one action?

ifconfig="mymodule/general/is_enabled"
ifconfig="mymodule/frontend/can_show"

Any suggestions would be most welcome.

4

There are 4 answers

0
Oscprofessionals On

ifconfig="mymodule/general/is_enabled" ifconfig="mymodule/frontend/can_show"

why not create an additional config node ifconfig="mymodule/frontend/is_enabled_can_show" and depending on this value proceed.

0
Ankita P. On

consider below scenario:

<catalog_category_default>
      <reference name="product_list">
          <action method="setTemplate" >
              <template>mymodule/mytemplate.phtml</template>
          </action>
     </reference>
</catalog_category_default>

ifconfig : If return value is false, then it takes layout defined in base folder.

helper function : If return value is false, then does not take layout defined in base folder, and not template gets added. that's why empty block is shown.

2
Slimshadddyyy On

You could use a helper method in your action parameter. Something like this

<action method="setTemplate">
    <template helper="mymodule/myhelper/canShowIf"/>
</action>

will call setTemplate with the results of a call to

Mage::helper('mymodule/myhelper')->canShowIf();

And the following in your modules default helper:

public function canShowIf()
{
    if($displayOnly = Mage::getStoreConfig('mymodule/general/is_enabled') == true)

    // Do Something

    }else if($displayOnly = Mage::getStoreConfig('mymodule/frontend/can_show') == true)         {

    // Do Something Else

   }
    return $displayOnly;
}

Implement your custom logic in canShowIf.

4
Asif hhh On

Define a function in Helper (Data.php)

  <reference name="root">
    <action method="setTemplate">
       <template helper="modulename/getNewLayoutupdate"/>
    </action>
  </reference>

in helper function you can load template by conditions.