Magento – How to add a custom block in Magento 2 System Configuration Group

magento2system-configsystem.xml

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.

Best Answer

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>