3

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.

Ankita P.
  • 478
  • 10
  • 21

4 Answers4

4

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.

Slimshadddyyy
  • 4,085
  • 5
  • 59
  • 121
  • This solution is working. But when function returns false, blank block is added. Either I want to work it same as "ifconfig". – Ankita P. Jan 02 '14 at 12:52
  • You can obviously have your IF-ELSE conditions and return parameters on what you want. Still you can paste your code here so that I can understand. – Slimshadddyyy Jan 02 '14 at 13:05
1

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.

Asif hhh
  • 1,552
  • 3
  • 15
  • 27
  • This solution is working. But when function returns false, blank block is added. Either I want to work it same as "ifconfig". – Ankita P. Jan 02 '14 at 12:50
  • well that depends upon your logic. what you want to do on false ? what is your goal exactly ? – Asif hhh Jan 02 '14 at 12:53
  • In case of ifconfig, if value is false, then it does not override the layout defined in base theme. But in case of helper function, if value is false false, then it overrides the layout defined in base folder. That's why it shows blank block. – Ankita P. Jan 02 '14 at 13:02
  • you have to check the value of a field, which is two possible value in your case and when its returns true that means the value is set from admin end and if it returns false then it should do the default behaviour – Slimshadddyyy Jan 02 '14 at 13:13
0

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.

Oscprofessionals
  • 2,161
  • 2
  • 15
  • 17
0

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.

Ankita P.
  • 478
  • 10
  • 21