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?

asked Jul 8, 2019 at 9:19
1
  • Can you provide a screenshot of what the config screen looks like? Commented Jul 8, 2019 at 20:28

1 Answer 1

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'); ?>"/>
answered Jul 9, 2019 at 10:04

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.