In Magento 1, to echo the store VAT number from a CMS page, I'd use {{config path="general/store_information/merchant_vat_number"}}. How do I do this in Magento 2?

1 Answer 1


You can create a custom widget to do this. Create a new module, Name_ConfigValueWidget.

In etc/widget.xml, use the following:

<widgets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    <widget id="config_value" class="Name\ConfigValueWidget\Block\Widget\ConfigValue"
        <label translate="true">Config Value</label>
        <description translate="true">Product Showcase</description>

            <parameter name="path" xsi:type="text" required="true" visible="true">
                <label translate="true">Path</label>


Now create the block class in Block/Widget/ConfigValue.php:


namespace Name\ConfigValueWidget\Block\Widget;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\View\Element\Template;
use Magento\Widget\Block\BlockInterface;

class ConfigValue extends Template implements BlockInterface
    protected $_scopeConfig;

    public function __construct(
        Template\Context $context,
        ScopeConfigInterface $scopeConfig,
        array $data
        parent::__construct($context, $data);

        $this->_scopeConfig = $scopeConfig;

    public function getValue()
        $path = $this->getData('path');

        return $this->_scopeConfig->getValue(

Now create the template file view/frontend/templates/configvalue.phtml:

    <?php /* @escapeNotVerified */ echo $block->getValue() ?>

After running setup:upgrade and clearing the cache, you can use this widget in a CMS page like this: {{widget type="Name\ConfigValueWidget\Block\Widget\ConfigValue" path="general/store_information/merchant_vat_number"}}

  • Hi Aaron, thank you for responding. I noticed you left some of your code in the above example - AAllen_Sandbox::configvalue.phtml. What should I put here, instead of AAllen_Sandbox? Thanks
    – MikeMason
    Commented Aug 5, 2016 at 21:20
  • 1
    Yeah, it should be whatever you defined the module as, for example Name_ConfigValueWidget::configvalue.phtml. Commented Aug 6, 2016 at 0:00

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.