0

I need to show field value in the label, not in the input box.

enter image description here

Please suggest for this

3 Answers 3

2

You need to add label type field in your system.xml :

app/code/Vendor/Module/etc/adminhtml/system.xml

<field id="expiry_date" translate="label" type="label" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0">
    <label>Expiry Date</label>
</field>

set label value in your 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>
                <expiry_date>Your values here</expiry_date>
            </group>
        </section>
    </default>
</config>

Output :

enter image description here

Flush cache and check output

2
  • Thanks! It works for me
    – Shomita
    Commented Nov 29, 2019 at 6:46
  • Happy to help !! You can accept answer if it's helpful for you. Commented Nov 29, 2019 at 6:50
3

you can add in app/code/Vendor/Module/etc/adminhtml/system.xml

<field id="test" translate="label" type="label" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
    <label>My Test lable</label>
</field>

in config.xml you can write

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>My test value</test>
            </group>
        </section>
    </default>
</config>

so will get out put like this

My Test lable My test value

Hope this will help you

0

You can add these lines in your system.xml file here in your custom module

app/code/Vendor/Module/etc/adminhtml/system.xml

You can add field like this..

<field id="label" translate="label" type="label" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
    <label>Test</label>
    <frontend_model>Vendor\Module\Block\Adminhtml\System\Config\Form\Field\Label</frontend_model>
</field>

You need to create one Block file now here on this path in your custom module

app/code/Vendor/Module/Block/Adminhtml/System/Config/Form/Field/Label.php

Content for this file is..

<?php
namespace Vendor\Module\Block\Adminhtml\System\Config\Form\Field;

class Label 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 _prepareLayout()
    {
        parent::_prepareLayout();
        if (!$this->getTemplate()) {
            $this->setTemplate('system/config/fieldset/custom_label.phtml');
        }

        return $this;
    }

    protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
    {
        return $this->_toHtml();
    }
}

Now you finally need to create one template file in your custom module here on this path..

app/code/Vendor/Module/view/adminhtml/templates/system/config/fieldset/custom_label.phtml

Content for this file is..

<label><?php echo __("Your label here"); ?></label>

Hope this will work for you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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