我正在努力创建一个我希望有一天能成为公开可用的 Magento 扩展的东西(我提到这一部分是因为我在这里做“正确的事”对我来说很重要)。我想做的一件事是在默认的 Magento 仪表板中添加一个框,基本上是一个新的“框”,与“前 5 个搜索词”完全相同,除了我自己的内容。我希望我的新自定义框成为最后显示的框(理想情况下)。
我遇到的问题是,负责渲染仪表板的模板调用要渲染的特定块,并且这些块嵌套在 html 内。换句话说,通常存在一个区域,子块将被渲染成一个漂亮合理的 HTML 元素,在这种情况下,似乎渲染了特定的块。这是内容/app/design/adminhtml/default/default/template/dashboard/index.phtml
<div class="dashboard-container">
<?php echo $this->getChildHtml('store_switcher') ?>
<table cellspacing="25" width="100%">
<tr>
<td><?php echo $this->getChildHtml('sales') ?>
<div class="entry-edit">
<div class="entry-edit-head"><h4><?php echo $this->__('Last 5 Orders') ?></h4></div>
<fieldset class="np"><?php echo $this->getChildHtml('lastOrders'); ?></fieldset>
</div>
<div class="entry-edit">
<div class="entry-edit-head"><h4><?php echo $this->__('Last 5 Search Terms') ?></h4></div>
<fieldset class="np"><?php echo $this->getChildHtml('lastSearches'); ?></fieldset>
</div>
<div class="entry-edit">
<div class="entry-edit-head"><h4><?php echo $this->__('Top 5 Search Terms') ?></h4></div>
<fieldset class="np"><?php echo $this->getChildHtml('topSearches'); ?></fieldset>
</div>
</td>
<td>
<div class="entry-edit" style="border:1px solid #ccc;">
<?php echo $this->getChildHtml('diagrams') ?>
<?php if (is_array($this->getChild('diagrams')->getTabsIds())) : ?>
<div id="diagram_tab_content"></div>
<?php endif; ?>
<div style="margin:20px;">
<?php echo $this->getChildHtml('totals') ?>
</div>
<div style="margin:20px;">
<?php echo $this->getChildHtml('grids') ?>
<div id="grid_tab_content"></div>
</div>
</div>
</td>
</tr>
</table>
</div>
如果我在自己的商店中执行此操作,我相信我可以通过编辑上面的基本 Magento 仪表板模板 index.phtml 相对轻松地实现此目的,添加我需要进行块渲染的内容,例如:
<div class="entry-edit">
<div class="entry-edit-head">
<h4><?php echo $this->__('Top 5 Search Terms') ?></h4></div>
<fieldset class="np"><?php echo $this->getChildHtml('myDashboardBox'); ?></fieldset>
</div>
</div>
但是,这不是我自己的商店,所以这似乎不是一个选择。
现在,经过一番思考,我的选择似乎如下(请注意,其中大多数看起来“不好”,而不是我在公众面前看到的超级自豪的东西):
0)很明显,我没有看到你会告诉我的是完美/正确的解决方案
1)我可能(也许?)能够将我的自定义块添加到该区域的其他块之一(“topSearches”、“sales”等)中,并渲染我的块。这看起来不太“干净”
2)我也许可以将该块呈现在仪表板页面上的其他位置,然后使用 javascript 将其移动到正确的位置。我猜这相当容易,但由于显而易见的原因,感觉非常“hacky”。
有没有人对执行此操作的方式有任何反馈,或者是否有办法?请记住,我想再次公开发布此模块,因此我的目标是做好工作并尽可能少地进行“黑客攻击”。
非常感谢您的阅读!