Magento-覆盖adminhtml模板文件 [英] Magento - Override adminhtml template file

查看:44
本文介绍了Magento-覆盖adminhtml模板文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了几篇关于堆栈溢出的文章

I have read several posts on stack overflow

  • Overriding a Magento Adminhtml template file
  • Magento - overriding Adminhtml block

和magento论坛上的一些话题

and a couple threads on the magento forum

但是,这些帖子都没有尝试做我想做的事情

However, None of these posts attempt to do what I am trying to do

我想覆盖

app/design/adminhtml/default/default/template/widget/grid.phtml 

文件,因为此文件包含html的一部分,该文件允许任何人从sales-> order视图中导出.

file, as this file contains a portion of html that allows anyone to export from the sales->order view.

注意:我们已在权限->角色视图中禁用了该用户角色的所有导出选项

Note: We have disabled all of the export options for this user role in the permissions->role view

我在上面列出的路径中包含显示导出到:"->"CSV/Excel XML"功能的代码.我想删除那部分html并覆盖Magento附带的文件.

The code that displays the "Export to: " -> "CSV/Excel XML" feature is included in the path I have listed above. I would like to remove that chunk of html and override the file included with Magento.

推荐答案

Adminhtml使用与前端相同的主题回退,因此,您只需要为模块config XML中的安装声明一个自定义模板主题:

Adminhtml uses the same theming fallback as the frontend, therefore you need only declare a custom template theme for your installation in module config XML:

<stores>
    <admin>
        <design>
            <theme>
                <template>custom</template>
            </theme>
        </design>
    </admin>
</stores>

然后,您可以根据自己的喜好创建 app/design/adminhtml/default/custom/template/widget/grid.phtml ,此文件将优先于默认/默认 adminhtml主题.然后,您的解决方案是在呈现导出控件的逻辑中添加ACL检查:

Then you can create app/design/adminhtml/default/custom/template/widget/grid.phtml with any customizations you like, and this file will be used in preference to the one from the default/default adminhtml theme. Your solution then would be to add an ACL check in the logic which renders the export control:

<?php if($this->getExportTypes() && {ACL LOGIC}}): ?>
    <td class="export a-right">
        <img src="<?php echo $this->getSkinUrl('images/icon_export.gif') ?>" alt="" class="v-middle"/>&nbsp; <?php echo $this->__('Export to:') ?>
        <select name="<?php echo $this->getId() ?>_export" id="<?php echo $this->getId() ?>_export" style="width:8em;">
        <?php foreach ($this->getExportTypes() as $_type): ?>
            <option value="<?php echo $_type->getUrl() ?>"><?php echo $_type->getLabel() ?></option>
        <?php endforeach; ?>
        </select>
        <?php echo $this->getExportButtonHtml() ?>
    </td>
<?php endif; ?>

虽然此逻辑可能在块类中更适当地实现,但是类重写系统无法容纳父类的重写,而您需要重写每个子类.在这种情况下,遵守DRY胜过在模板中嵌入太多逻辑.而且,这种变化是显而易见的,并且易于维护.

While this logic might be more appropriately implemented in the block class, the class rewrite system does not accommodate rewriting of parent classes, leaving you to rewrite every subclass. In this instance, obeying DRY outweighs embedding too much logic in templates. Moreover, the change is obvious and easily maintained.

理想情况下,核心团队应该在Mage_Adminhtml_Block_Widget_Grid类中执行此检查,或者至少为_exportTypes属性提供公共设置器,这会使该逻辑更易于实现.

Ideally the core team would have implemented this check in the Mage_Adminhtml_Block_Widget_Grid class or at least provided a public setter for the _exportTypes property, which would have made this logic a bit cleaner to implement.

这篇关于Magento-覆盖adminhtml模板文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆