Magento 2: Add text in system.xml
-
08-10-2020 - |
Question
Is it possible to have plain text next to the label in system config instead of an input field, something like:
<field>
<label>Hey you</label>
<plainText>Lorem ipsum...</plainText>
</field>
The closest I can get is using a label, but thats looks bad when I have more than 4 words in it. This is what it should look like:
Solution
system.xml
<field id="test" translate="label" type="label" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Hey you!</label>
</field>
config.xml
app/code/Vendor/Module/etc/config.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<section>
<group>
<test>Your values here</test>
</group>
</section>
</default>
</config>
OUTPUT:
OTHER TIPS
I also wanted to add custom text in store configuration and found below simple way to add custom text:
<field id="test" translate="label" type="label" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<label>NOTE: </label>
<comment>Your Custom TEXT Here...</comment>
</field>
Hope will be helpful for someone.
system.xml
<field id="test" type="label">
<label>Test</label>
</field>
in config.xml define it's value
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<groupname>
<settings>
<test>values</test>
</settings>
</groupname>
</default>
</config>
Use CDATA[]
if neeed
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange