0

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 Jan 5 '17 at 7:10
0

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 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 Dec 30 '16 at 11:07
  • view\adminhtml\templates\system\config\advance\YOUR_FILE.phtml – Keyur Shah Dec 30 '16 at 11:11
  • Any reason @GauravAgrawal :) – Keyur Shah Dec 30 '16 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 Dec 30 '16 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 Jan 2 '17 at 7:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.