I am trying to add a text block in Magento 2 system configuration group.
I want to write some hints for the users in a separate group. As it can be done in Magento 1.
Here is my screenshot what I actually want.
Magento 1.x System Configuration Group's Block
Still, I am waiting for any response. Is there anyone who has done this before in Magento 2?
Please let me know about this.
Thanks in Advance.
-
Anyone found solution for this?Gaurav Agrawal– Gaurav Agrawal2017年01月05日 07:10:20 +00:00Commented Jan 5, 2017 at 7:10
1 Answer 1
You can use the <frontend_model> feature of system configuration. here is the example
<field id="YOUR_NAME" showInDefault="1" showInWebsite="1" showInStore="1" sortOrder="100">
<frontend_model>VENDOR\MODULE_NAME\Block\Adminhtml\System\Config\Advanced</frontend_model>
<attribute type="shared">1</attribute>
</field>
and your block file should contain this code
<?php
namespace VENDOR\MODULE_NAME\Block\Adminhtml\System\Config;
class Advanced extends \Magento\Config\Block\System\Config\Form\Field
{
/**
* Template path
*
* @var string
*/
protected $_template = 'system/config/advance/YOUR_FILE.phtml';
/**
* Render fieldset html
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
*/
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
$columns = $this->getRequest()->getParam('website') || $this->getRequest()->getParam('store') ? 5 : 4;
return $this->_decorateRowHtml($element, "<td colspan='{$columns}'>" . $this->toHtml() . '</td>');
}
}
And in your view\adminhtml\templates\system\config\advance\YOUR_FILE.phtml file you can write anything which you want
<div>
<?php echo __('Hello WOrld'); ?>
</div>
-
Can you tell me where to keep this phtml file.Gaurav Agrawal– Gaurav Agrawal2016年12月30日 11:07:56 +00:00Commented Dec 30, 2016 at 11:07
-
view\adminhtml\templates\system\config\advance\YOUR_FILE.phtmlKeyur Shah– Keyur Shah2016年12月30日 11:11:15 +00:00Commented Dec 30, 2016 at 11:11
-
Any reason @GauravAgrawal :)Keyur Shah– Keyur Shah2016年12月30日 13:53:11 +00:00Commented Dec 30, 2016 at 13:53
-
Hey Keyur, I am not able to check your answer after implementation. because of some access issue. So whenever I will check and complete it. Will update here.Gaurav Agrawal– Gaurav Agrawal2016年12月30日 13:59:49 +00:00Commented Dec 30, 2016 at 13:59
-
Hey Keyur, I have tried your solution today. And it not worked for me. It shows a black page after adding code provided by you.Gaurav Agrawal– Gaurav Agrawal2017年01月02日 07:35:04 +00:00Commented Jan 2, 2017 at 7:35