1

I've written a function that uses debug_backtrace() to find which methods were called in which PHP files to eventually load a given Block. (Look for the blockBacktrace method in the Helper class here.)

What I want to do is reverse engineer the layout to be able to find out which layout XML file declared a given block and defined what block should be it's parent. While it's not a requirement, I would also love to be able to detect blocks which were generated by the CMS and have their XML stored in the database.

Is there a good way available in Magento to reverse engineer the layout to get this information from within a block? My eventual goal is to be able to call a Helper method from within a block which generates output that tells the developer how that block came to be where it is.

Thank you.

  • 1
    This would be nice to know, however, Magento compiles the xml into one large stack, so as far as the file of origin, I do not believe it retains this information. As for the parent block, you may find this useful: stackoverflow.com/questions/6949382/… – DWils Apr 15 '14 at 1:17
  • @DWils. You can write your comment as an answer. – Marius Jun 2 '14 at 9:06
  • Thanks, but I did not feel it provides enough information to completely answer the question. – DWils Jun 3 '14 at 19:27
2

Is there a good way available in Magento to reverse engineer the layout to get this information from within a block?

The only thing which you can do is map an instance to its likely declaration in the layout DOM, and from there list the possible directives & files involved. Not perfect, but you can use the block's name attribute to help. This is complicated by the ability to declare more than one block with the same name. Of course there are lots of anonymous blocks as well as blocks created at runtime directly in PHP (in addition to CMS).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.