1

I want to know how we get the path of a config status for a natif and a custom module.

Assuming that i want to get a config path of:

1) System>Configuration>Design>View demo store warning message> No.

2) System>Configuration>Web>Add store code to URLs> Yes.

3) System>Configuration>CustomModule>CustomField> 1.

My layout.xml:

<?xml version="1.0"?>
<layoutupdate>
    <catalog_product_view>
        <reference name="head">
             <action method="addItem" ifconfig="path/to/config/status/enabled" condition="1"><type>skin_js</type><name>js/script_one.js</name></action>
              <action method="addItem" ifconfig="path/to/config/status/enabled" condition="0"><type>skin_js</type><name>js/script_two.js</name></action>
        </reference>
   </catalog_product_view>
</layoutupdate>
| improve this question | | | | |
4

System configuration paths are split into three (3) parts: Section, group and field. When reading the configuration, the path is constructed as: section/group/field. There are two ways to find these pieces of information out:

Inspecting the form and URL

I find this to be the easiest unless I know what module the configuration I'm looking for comes from. This is due to the fact that Magento 1.x has it's modules span multiple configuration areas and it's not always obvious which module goes to which configuration.

The easiest way I know of is to piece it together from the URL and the form, since usually I'm looking at the configuration as I'm adding a constraint to my layout.

If you look at the URL, you'll see it specifies the section like: index.php/admin/system_config/edit/section/design/. The important part is the section/design part. This gives you the first part of the configuration path, the section: design

Next you would need to inspect the input field you want to reference. For this example I'll use the demo store notice. If you inspect this field, you'll see a name like this: groups[head][fields][demonotice][value]. The important part here is before the value between the square brackets after groups and before [fields]. This gives you the group of the configuration path: head

The last piece is the actual name of the configuration variable. This will be the value between the square braces between the [fields] and [value] of the input field. So for this example the value of the third and final element is: demonotice.

So the configuration path you would use is: design/head/demonotice

Reading the system.xml file of the correct module

The alternative way to look this up is to open the system.xml of the corresponding module. If you look in the system.xml file of the Magento_Page module you'll find the following XML:

<config>
  <sections>
    <design ...>
      <groups ...>
        <head ...>
          <fields ...>
            <demonotice ...>
            </demonotice>
          </fields>
        </head>
      </groups>
    </design>
  </sections>
</config>

So you'd need to find the configuration name you want, in this case demonotice and follow it up the tree to find the group name, in this case head and follow that up to the containing section name, in this case design.

So the resulting configuration path would be design/head/demonotice.

| improve this answer | | | | |
1

Brett is completely right, but you can get config path easily from browsers inspector.

Just inspect the input field your are interesset in and you'll see something like this:

enter image description here

The id selector represent the full config path and if your config path contains underscores you can also take a look at name attribute.

Limitations using ifconfig:

Unfortunately there are no condition parameters in layout files, ifconfig always returns a boolean value, see Mage_Core_Model_Layout ...

protected function _generateAction($node, $parent)
{
    if (isset($node['ifconfig']) && ($configPath = (string)$node['ifconfig'])) {
        if (!Mage::getStoreConfigFlag($configPath)) {
            return $this;
        }
    }
    ...
}

So you can only check if config is set to 0 or 1. If you want to check the explicit value you have to create a helper method and adjust layout to something like this:

<reference name="head">
    <action method="addItem">
        <item helper="module/helper/method"/>
    </action>
</reference>

Using free Extended ifconfig extension should allow you to add condition parameters.

| improve this answer | | | | |
  • Thank you for your answer, it is simpler, However as Brett did a well explained stuff I validate his answer but +1 ;) . You told that there is no condition in if config, assuming that i have in my field three values 1, 2, 3 so i can do some condition for exemple display my block if the value of my field is 3 condition="3" – PЯINCƏ May 22 '17 at 8:36
  • Updated my answer. – sv3n May 22 '17 at 8:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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