Properly override a admin template file in Magento

Properly override a admin template file in Magento

September 13, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Properly override a admin template file in Magento

Overriding Magento Admin Templates: A Step-by-Step Guide

Are you struggling to override an admin template file in your Magento project? You’re not alone! This common task can be confusing if you don’t understand how Magento’s layout system works.

Let’s start by understanding the basics of Magento templates. In the core, you have the app/design/adminhtml/default/default directory structure where all the default admin templates are stored.

Now, let me show you the proper way to override an admin template file:

Step 1: Create Your Module

First, create a new module in your app/code directory. Let’s name it MyNamespace_AdminTemplate. This will be used as a container for our customizations.

mkdir -p app/code/MyNamespace/AdminTemplate

Step 2: Create the Layout File

Inside this new module, navigate to the etc directory and create an XML layout file named adminhtml.xml.

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/layout.xsd">
  <layout>
    <!-- Place your layout rules here -->
  </layout>
</config>

Step 3: Reference the Custom Template

Now, within the <layout> node in adminhtml.xml, you’ll reference the custom template file. Here’s an example for overriding the address.phtml file:

<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/layout.xsd">
  <update handle="sales_order_create_index"/>
  <referenceBlock name="sales.order.create.form.address" template="MyNamespace_AdminTemplate::form/address.phtml"/>
</layout>

In this example, we first update the layout to use the sales_order_create_index handle. Then, we reference the sales.order.create.form.address block and specify our custom template path.

Step 4: Create the Custom Template

Next, create a new directory structure under your module’s template folder:

app/code/MyNamespace/AdminTemplate/view/adminhtml/templates/sales/order/create/form

Inside this directory, create a file named address.phtml. This is where you’ll place your custom HTML code.

<!-- Your custom HTML for the address field goes here -->
<div class="field">
  <label for="billing_address_id" class="required"><span><?= __('Billing Address') ?></span></label>
  <?php echo $block->getAttributeHtml('billing_address_id', 'order_billing_address_id_'); ?>
</div>

Step 5: Enable Your Module

Finally, don’t forget to enable your new module in the Magento backend. Navigate to Stores > Configuration > Advanced > Modules and find MyNamespace_AdminTemplate. Click “Enable” to activate it.

Conclusion

And that’s how you properly override an admin template file in Magento! Remember, always keep your customizations separate from the core files using this extensibility approach.

For more advanced techniques like adding JavaScript or CSS to your layout, I recommend checking out our guide on Magento 2 customization at Laravel Company.

Happy coding! Let me know if you have any other questions.

Extensions Themes Admin Configuration

Our network