Overriding the Adminhtml template file in Magento
In Magento, overriding adminhtml template files involves some specific steps that differ from the standard theme override process. If you’re trying to modify the widget/grid.phtml file located at app/design/adminhtml/default/default/template, here’s a step-by-step guide on how to achieve this.
Firstly, let me address your concern about disabling export options via permissions->role view. While this is a good starting point, it doesn’t directly control the rendering of the HTML that displays the export links in the sales->order view. You’re correct that you need to override the specific template file where the export links are rendered.
Creating an adminhtml theme
To override an adminhtml template, you’ll first need to create a custom adminhtml theme. This is different from creating a frontend theme for customers seeing your store’s website.
- Create the theme directory: In your Magento root folder, navigate to
app/design/adminhtmland create a new folder for your theme, e.g.,mycustomtheme. Inside this folder, create another folder calleddefault.
cd app/design/adminhtml
mkdir mycustomtheme
cd mycustomtheme
mkdir default
- Copy the original template: Navigate to the
widgetfolder in the Magento root directory and copy thegrid.phtmlfile.
cp app/code/core/Mage/Adminhtml/view/base/templates/widget/grid.phtml app/design/adminhtml/mycustomtheme/default/template/
- Add theme information: Create a new file called
theme.xmlinside thedefaultfolder within your custom adminhtml theme and add the following content:
<?xml version="1.0"?>
<theme>
<title>My Custom Admin Theme</title>
<parent>base/default</parent>
<media>default</media>
<theme_path>/mycustomtheme/default/</theme_path>
</theme>
Overriding the grid.phtml file
Now that you have your custom adminhtml theme set up, let’s override the grid.phtml file:
-
Open the copied
grid.phtmlfile located inapp/design/adminhtml/mycustomtheme/default/template/widget/. -
Locate the HTML portion responsible for displaying the “Export to:” options (around line 83). It looks something like this:
<div class="export-block">
<label><span class="label"><?php echo ($this->getIsExcel()) ? $this->__('Export To:') : $this->__('Export To Excel:') ?></span></label>
<?php if($this->getIsExcel()): ?>
<input type="button" onclick="" value="<?php echo $this->__('CSV/Excel XML') ?>" class="export-link" />
<?php else: ?>
<a href="#none"><?php echo $this->__('XML (without columns)') ?></a> | <a href="#none"><?php echo $this->__('CSV (with columns)') ?></a>
<?php endif; ?>
</div>
- To remove the export links, simply delete this entire
export-blockdiv.
Conclusion
After following these steps, you should have successfully overridden the widget/grid.phtml file in your Magento adminhtml theme. This will allow you to customize or remove specific HTML elements directly from the backend interface without altering any core files.
Remember that creating a custom adminhtml theme also allows you to override other administrative templates and layouts as needed. You can find more information about this process in our comprehensive guide on customizing your Magento admin panel.
Always ensure you make a backup of your files before making changes, especially when dealing with core Magento templates or themes.
That’s it! I hope this helps clarify the process for overriding adminhtml template files in Magento.