Add Backend (Admin) Template in Magento 2

Published Thursday, January 16, 2020

Adding a template to the admin area is basically the same as the frontend. The difference is the layout and template files go in the "adminhtml" folder (instead of the "frontend" folder).

File List

  • Joki/BackendTemplate/registration.php
  • Joki/BackendTemplate/etc/module.xml
  • Joki/BackendTemplate/view/adminhtml/layout/sales_order_create_index.xml
  • Joki/BackendTemplate/view/adminhtml/templates/sales/order/create/new-section.phtml

registration.php [copy] [view]

 
  1<?php
  2use \Magento\Framework\Component\ComponentRegistrar;
  3
  4ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Joki_BackendTemplate', __DIR__);
 

etc/module.xml [copy] [view]

 
  1<?xml version="1.0"?>
  2<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
  3    <module name="Joki_BackendTemplate" />
  4</config>
 

view/adminhtml/layout/sales_order_create_index.xml [copy] [hide]

  1<?xml version="1.0"?>
  2<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
  3    <body>
  4        <referenceContainer name="content">
  5            <block class="Magento\Framework\View\Element\Template" name="sales_order_create_new_section" template="Joki_BackendTemplate::sales/order/create/new-section.phtml" before="-" />
  6        </referenceContainer>
  7    </body>
  8</page>

view/adminhtml/templates/sales/order/create/new-section.phtml [copy] [hide]

  1<section class="admin__page-section">
  2    <div class="admin__page-section-title">
  3        <strong class="title">New Section</strong>
  4    </div>
  5    <div class="admin__page-section-content">
  6        <p>Content goes here.</p>
  7    </div>
  8</section>

Here's a screenshot of the new section on the order-create page.