我正在努力创建我希望有一天会成为公开可用的 Magento 扩展的东西(我提到这部分是因为我在这里做“正确的事情”对我很重要)。我想做的一件事是在默认的 Magento 仪表板中添加一个框,基本上是一个新的“框”,与“Top 5 Search Terms”完全一样,除了我自己的内容。我希望我的新自定义框成为显示的最后一个框(理想情况下)。
我遇到的问题是负责渲染仪表板的模板调用了要渲染的特定块,这些块嵌套在 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”。
有没有人对这样做的方式有任何反馈,或者如果有办法?请记住,我想再次公开发布这个模块,所以我的目标是做好工作并尽可能少地“黑客”。
非常感谢您的阅读!