Add custom block in Magento 2 admin dashboard
-
03-01-2021 - |
Solution
You can try to create a custom module that adds the a block there. Create:
\app\code\Custom\Module\registration.php:
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Custom_Module',
__DIR__);
\app\code\Custom\Module\etc\module.xml:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Custom_Module" setup_version="1.0.0">
</module>
\app\code\Custom\Module\view\adminhtml\layout\adminhtml_dashboard_index.xml:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="Magento\Framework\View\Element\Template" name="custom.block" after="-" template="Custom_Module::custom.phtml"/>
</referenceContainer>
</body>
\app\code\Custom\Module\view\adminhtml\templates\custom.phtml:
<?php
echo 'custom code here';
Don't forget to run:
php bin/magento setup:upgrade
php bin/magento cache:flush
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange