How to Add Dynamically Generated Comment for a Backend Configuration Field in Magento 2

How to Add Dynamically Generated Comment for a Backend Configuration Field in Magento 2 4

As a Magento 2 developer, you may need to add comments in the backend configuration of extensions for the ease of admin or store owner. The extension holder might not be an expert in Magento 2 and hence such comments can guide them through the extension configuration and use.

However, in particular cases, the comments can have links to the store’s URLs to show the output or redirect the admin to check the functionality implemented in the backend.

But, these links’ paths differ from one Magento 2 store to another. The extension that you are going to develop is not necessarily going to be used for a single store only. Hence you need to add dynamically generated comment for a backend configuration field in Magento 2.

The post shows how to do so programmatically.

Method to Add Dynamically Generated Comment for a Backend Configuration Field in Magento 2:

  1. Create system.xml at app\code\Vendor\Extension\etc\adminhtml


  2. Create DynamicComment.php at app\code\Vendor\Extension\Block\Adminhtml\System folder

That’s it.

I’ve implemented the above method as shown here:

How to Add Dynamically Generated Comment for a Backend Configuration Field in Magento 2 5

 

Now you can fill your backend configuration with dynamic comments 😄

Feel free to post your doubts in the Comments section below and I’d be happy to help.

I’d be very grateful if you helped share this helpful post on social media to fellow developers!

Thanks!

 

5
(based on 9 Reviews)

Sanjay is a co-founder at Meetanshi. He is a certified Magento developer who loves creating Magento E-commerce solutions. When he is not engrossed with anything related to Magento, he loves to play cricket.

Leave a Reply