Magento 2 System.xml – Display HTML Content in system.xml Configuration

magento2modulesystem.xml

i want to show some htmlContent in configuration. System.xml. how it could be?

Best Answer

you can append html with following ways

<field id="test" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Some Test</label>
                    <comment><![CDATA[test contet]]></comment>
                    <frontend_model>Test\Module\Block\Test</frontend_model>

                </field>

block code

<?php
namespace Test\Module\Block;

class Test extends \Magento\Config\Block\System\Config\Form\Field {


    public function __construct(
    \Magento\Backend\Block\Template\Context $context, array $data = []
    ) {
        parent::__construct($context, $data);
    }

    protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element) {
        $html = $element->getElementHtml();
        $value = $element->getData('value');

        $html .= 'use your logice here';
        return $html;
    }

}