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?
-
Can you provide a screenshot of what the config screen looks like?Dominic Pixie– Dominic Pixie2019年07月08日 20:28:38 +00:00Commented Jul 8, 2019 at 20:28
1 Answer 1
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'); ?>"/>
Explore related questions
See similar questions with these tags.