-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Debug layout file processing by print final merge layout xml ? #10533
Comments
Or just use xdebug. It allows to check state of any variable in action and not just try to guess what needs to be echoed/printed to file. |
Hi Orlangur, |
You don't need this, just learn to debug properly, without need for any hardcoded logging. |
I have had to use logging debugging like this before, and debugging like this does have its merit. For a lot of scenarios xdebug and object inspection is the usual debugging tool, but for others dumping to a log file has definitely saved me. Saying that, I'd still probably roll this logging out bespoke as and when it's needed, as next time when you need to debug different merged xml your layout xml logger won't be useful. I'd never have thought of adding this kind of tool to the core. |
Hi, |
Whoa I thought this would be a really good addition as a bin/magento command. |
Hi Miguelbalparda, |
@miguelbalparda agree that it would be a good addition to the You could have a have a lot of fun with the eg |
Now, I reopen it again... Let see the response from Magento |
You and I know MageRun @convenient but new devs coming here only know about bin/magento when they start, so adding this to the core might be wise no matter if it is already in MageRun. I used a similar approach in Magento 1 more times than I'd like to admit. |
Good point @miguelbalparda :) |
@thienphucvx if you want to have a go at implementing the |
@thienphucvx Thank you for your report. |
@thienphucvx we are closing this issue due to inactivity. If you'd like to update it, please reopen the issue. |
Although this issue is closed already, I came across it and know that there is a workaround, so want to share it here. Layout is cached by Magento. We can debug the layout by inspecting the layout cache. To use this workaround:
A hit or more will show you the layout cache of the current page being debugging. |
This would be very useful |
The fact that there is no easy way to view the layout on any given page makes debugging the cryptic layout system even more tedious. The spirit of this feature should be understood by the core team, how about a simple way to dump the layout XML for any given page. After all we already have template path hints... |
Those path hints are not great. |
Yup, template path hints are borderline useless. Just pointing out to the core team that there is a built-in debugging tool. Furthermore suggesting a similar simple tool (checkbox in the admin / flag we can set on the cli) to enable dump of layout xml on the frontend would be vastly more useful. |
There are third party modules attempting to solve the issue. I've found two: |
To add to this, Ho_Templatehints is another module that lets you inspect layout via DevTools in a somewhat unobtrusive way. |
At some point, you want to print all loaded xml files to check whether your custom layout is working or not ?
In order to do that we can write a custom module like this to solve that problem:
1/ We create a new directory Sample/Dev. Create Sample/Dev/registration.php to declare with Magento
2 about our module directory.
`<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Sample_Dev',
DIR
);`
2/ Create Sample/Dev/etc/module.xml : To let Magento 2 know about setup version of our module:
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="module.xsd"> <module name="Sample_Dev" setup_version="1.0.0" schema_version="1.0.0" release_version="1.0.1"> </module> </config>
3/ Create Sample/Dev/etc/frontend/events.xml. In this file, we will listen to event “layout_generate_blocks_after”
`
4/ Create Sample/Dev/Model/Layout.php with the content as below
`<?php
namespace Sample\Dev\Model;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
class Layout implements ObserverInterface
{
protected $_logger;
public function __construct ( \Psr\Log\LoggerInterface $logger
) {
$this->_logger = $logger;
}
}`
5/ Set up new module . In your home website directory. enter CMD command line:
– php bin/magento module:enable Sample_Dev
– php bin/magento setup:upgrade
6/ Refresh the page that you want to see xml file and check your handle xml file in var/log/layout_block.xml .
I just wonder if we can have it as a default module in magento2 => So we can turn on/off to debug easily.
Reference:
https://magento.stackexchange.com/questions/97343/how-can-i-debug-layout-file-processing-in-magento-2/98078?noredirect=1#comment261437_98078
The text was updated successfully, but these errors were encountered: