Magento子html——获取父调用者

发布于 2024-11-28 03:41:14 字数 305 浏览 1 评论 0原文

我在模板文件 price.phtml 中。我想要一些代码行来查看调用该块的父级并基于此执行一些行为。本质上,如果父级是目录列表页面,我希望将 from: 标记添加到价格中。如果父级是 configurable.phtml,我只想正常显示价格。

我已经有了将 from: 添加到价格的代码,但我需要 if 语句来告诉父调用者是什么。

我之前在阅读 Mage 文件时见过类似 ::parent 的东西,但我不知道这是否适用于这里......

谢谢!

I am in the template file price.phtml. I would like to have some line of code that looks at the parent that is calling the block and do some behavior based on that. Essentially if the parent is a catalog list page, I want a from: tag to be added to the price. If the parent is configurable.phtml, I want to simply display the price as normal.

I already have the code to add the from: to the price but I need the if statement to tell what the parent caller is.

I have seen something like ::parent before when perusing Mage files, but I don't know if that is applicable here...

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怀念你的温柔 2024-12-05 03:41:14

您可以通过调用从 phtml 获取对块的父块的引用

$parent = $this->getParentBlock();

parent::someMethod 的调用与块或 Magento 无关。它们是 PHP 构造,用于指示您想要调用父类上的方法。

YOu can get reference to a block's parent block from a phtml by calling

$parent = $this->getParentBlock();

The calls to parent::someMethod have nothing to do with blocks, or with Magento. They're PHP constructs, used to indicate you want to call a method on the parent class.

面如桃花 2024-12-05 03:41:14

这里有很多方法可以帮助您了解在 Magento 中可视化的页面类型:

  • 当前 CMS 页面:Mage::getSingleton('cms/page')->getIdentifier();
  • 当前路由:Mage::app()->getFrontController()->getRequest()->getRouteName();
  • 当前控制器: Mage::app()->getFrontController()->getRequest()->getControllerName();
  • 当前操作:Mage::app()->getFrontController() ->getRequest()->getActionName();

因此,例如,如果您想了解自己位于目录列表页面,您可以使用最后三个,用于检查路由是否为目录,控制器是否为类别,操作是否为查看

另一种方法包括检查当前布局句柄数组中是否存在 catalog_category_view 布局句柄,您可以通过以下方式从块或模板中检索该句柄: $this->getLayout()->getUpdate()->getHandles()

希望有帮助。

问候, 亚历山德罗

here is a bunch of methods that can help you understanding which kind of page you are visualizing in Magento:

  • Current CMS Page: Mage::getSingleton('cms/page')->getIdentifier();
  • Current Route: Mage::app()->getFrontController()->getRequest()->getRouteName();
  • Current Controller: Mage::app()->getFrontController()->getRequest()->getControllerName();
  • Current Action: Mage::app()->getFrontController()->getRequest()->getActionName();

So, for example, if you want to understand you are in a catalog list page you can use the last three in order to check whether the route is catalog, the controller is category and the action is view.

Another method would consist in checking for the presence of a catalog_category_view layout handle in the array of current layout handles that you can retrieve in the following way from a Block or a Template: $this->getLayout()->getUpdate()->getHandles()

Hope it helps.

Regards, Alessandro

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文