1

Is there any way to add a custom block in magento 2 admin dashboard? I have a requirement to add custom table in dashboard. Can anyone help me?

enter image description here

My current magento version 2.2.1

6

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

  • 1
    This worked, but instead I used <referenceContainer name="header"> to insert custom block into the admin header area – BENN1TH Sep 22 '18 at 23:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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