Magento - xml layouts, specify ifconfig value?

I'm sure I saw somewhere by specifying a value for the ifconfig xml instructions (by default, this is just a boolean). In any case, disabling the modules in the administrator does not actually work (disables only the output of the module). But you can add ifconfig to your layout file, for example, to install a template only if the module is disabled it looks like this:

<action method="setTemplate" ifconfig="advanced/modules_disable_output/Myname_Mymodule"> <template>mytemplate.phtml</template> </action> 

So, how could you invert this, so the template is installed only if the module is enabled ? Sort of:

 <action method="setTemplate" ifconfig="advanced/modules_disable_output/Myname_Mymodule" value="0"> <template>mytemplate.phtml</template> </action> 
+6
source share
2 answers

This fits nicely with something (self-link) I was working on.

You cannot do what you want without rewriting the class to change the behavior of ifconfig . Here is the code that implements the ifconfig function.

 File: app/code/core/Mage/Core/Model/Layout.php protected function _generateAction($node, $parent) { if (isset($node['ifconfig']) && ($configPath = (string)$node['ifconfig'])) { if (!Mage::getStoreConfigFlag($configPath)) { return $this; } } 

If ifconfig is detected and the config value returns true, the action method will not be called. You can rewrite _generateAction and implement your own conditional expression, but then the standard burden of rewriting support disputes you.

A better approach would be to use a helper method in your action parameter. Something like that

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

will call setTemplate with call results

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

Embed your own logic in switchTemplateIf , which will either save the template or change it, and you will be good to go.

+21
source

You can create a separate enable parameter using only the system.xml module.

 <config> <sections> <advanced> <groups> <YOURMODULE> <fields> <enable> <label>YOUR MODULE</label> <frontend_type>select</frontend_type> <source_model>adminhtml/system_config_source_enabledisable</source_model> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> </enable> </fields> </YOURMODULE> </groups> </advanced> </sections> </config> 

Then use the new parameter in the layout file:

 <action method="setTemplate" ifconfig="advanced/YOURMODULE/enable"> <template>mytemplate.phtml</template> </action> 
+8
source

Source: https://habr.com/ru/post/885514/


All Articles