【发布时间】:2012-03-02 09:39:15
【问题描述】:
我正在努力创建我希望有一天能成为公开可用的 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”。
是否有人对这样做的方式有任何反馈,或者如果有办法吗?请记住,我想再次公开发布这个模块,所以我的目标是做好工作并尽可能少地“黑客”。
非常感谢您的阅读!
【问题讨论】:
-
我一直在寻找 0) 解决方案已经有一段时间了,但没有运气。到目前为止,我想出的最好的方法是通过观察 html 渲染,但它涉及到
str_replace(),它看起来永远不会很干净。如果你有兴趣,我可以解释一下我是怎么做的。 -
嘿,感谢 OSdave 的回复!我想我可以想象 str_replace 方法是如何工作的,但我可能会将它与我的其他解决方案一起包括在内,因为(显然)有点“hacky”。目前(我只花了几个小时试图弄清楚这一点)我个人最好的解决方案可能是 JS 解决方案,仅仅是因为大多数人都会有 JS,我也许可以在其他地方渲染盒子并拥有它在 JS 由于某种原因无法工作的情况下看起来不错,但是如果将其移动到需要的位置。不过,我希望有人能睁开我的眼睛;)
标签: templates magento dashboard block adminhtml