如何跟踪 Magento 从哪里调用模板?
我正在与 Magento 合作。请参阅以下代码:
<?php echo $this->getChildHtml('topMenu') ?>
是否有一种简单的方法可以找到 HTML 所在的位置。即我可以使用某种痕迹吗?
I'm working with Magento. See the following code:
<?php echo $this->getChildHtml('topMenu') ?>
Is there an easy way to find where HTML resides. I.e. is there some kind of trace I can use?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在管理中转到系统>;配置>开发者,从左上角的“配置范围”选择中选择一个商店,然后“调试”部分会出现一个名为“模板路径提示”的新选项。打开此功能并再次刷新您的商店页面。
Magento 设计者指南中对此以及更多内容进行了解释。
In the admin go to System > Configuration > Developer, pick a store from the "Configuration Scope" select in the top left corner, then there will be a new option in "Debug" section called "Template Path Hints". Turn this on and refresh your store page again.
This and more is explained in the Designer's Guide to Magento.
我完全同意clockworkgeek的回答 - 最简单的方法是在系统 -> 中打开模板路径提示配置->管理面板的开发人员部分(必须选择商店范围才能显示此字段)。之后,您的所有商店页面都将呈现包含红色面板的内容,显示模板的路径。
不错的补充是在上面提到的管理部分中打开将块名称添加到提示 - 这样您还会看到为该模板提供服务的块名称。
这些操作将使您轻松追踪所有设计的 95%。
然而,也有一些块不渲染 phtml。或者它们以不显示模板路径的方式重载标准 toHtml() 方法。这些都是更复杂的情况。要找到创建设计的位置,您应该:
学习 Magento 中视图部分的布局块-phtml 模型 - Magento 设计师指南 是学习它的好地方。然后,您将能够通过布局结构查找块和模板。
安装 X-Debug,为您的 IDE 设置它,在
getChildHtml('topMenu') ?>
行设置断点并挖掘此内容线。这是解决问题的最简单、最通用的方法(尽管仍然必须了解 Magento 设计结构)。I fully agree with the answer of clockworkgeek - the easiest way is to turn on Template Path Hints in System -> Configuration -> Developer section of admin panel (scope of your store must be chosen for this field to appear). After that all your store pages will be rendered with inclusions of red panels, showing the path to templates.
Nice addition is also to turn on Add Block Names to Hints in the mentioned above admin section - so you'll also see block names serving that templates.
These actions will allow you to easily trace 95% of all design.
However, there are also some blocks that do not render phtml. Or they overload standard toHtml() method in such a way that it doesn't show template's path. These are more complicated cases. To find the place where design is created you should either:
Learn layout-blocks-phtml model of View part in Magento - Designer's Guide to Magento is a good place to study it. Then you'll be able to find blocks and templates by layout structure.
Install X-Debug, set it up for your IDE, set a breakpoint at
<?php echo $this->getChildHtml('topMenu') ?>
line and dig in this line. It's the easiest and most universal way to solve your problem (although knowledge of Magento design structure still is a must).