0

I have a custom phtml file in system config and been added to 3 groups:

group_1, group_2, group_3

in phtml I have:

<input id="my_value" type="number" name="groups[group_1][groups][my_settings][fields][my_value][value]" value="<?= $block->getValue('my_value'); ?>"/>

Where name=group[group_1] should be dinamically depending on which group it it belongs: for example: groups[<?= $GROUP ?>][groups][my_settings][fields][my_value][value]

Where $GROUP will hold value for each group:

It works if I hard coded for one for group e.g: groups[group_1]

How can I get groups name programatically?

1
  • Can you provide a screenshot of what the config screen looks like? Jul 8 '19 at 20:28
0

I manage to find out by simply using $element->getName() in render:

public function render(AbstractElement $element)
    {
        //print_r($element->getName());//this will print full path on every group correctly.
        $this->_pathGroupName = $element->getName(); 
        $element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
        return parent::render($element);
    }

public function getPath() {
        return $this->_pathGroupName;
    }

In my phtml:

...    
<input id="<= $key ?>" type="number" value="<?= $block->getValue() ?>" name="<?= $block->getPath();?>" /> 
...

I then ended up with in my inputs like:

<input id="0" type="number" name="groups[group_1][groups][my_settings][fields][my_value][value]" value="<?= $block->getValue('my_value'); ?>"/>

<input id="1" type="number" name="groups[group_2][groups][my_settings][fields][my_value][value]" value="<?= $block->getValue('my_value'); ?>"/>

<input id="2" type="number" name="groups[group_3][groups][my_settings][fields][my_value][value]" value="<?= $block->getValue('my_value'); ?>"/>

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.