{"id":21076,"date":"2019-05-13T11:59:42","date_gmt":"2019-05-13T11:59:42","guid":{"rendered":"https:\/\/blog.jetbrains.com\/phpstorm\/?p=14327"},"modified":"2024-01-09T14:51:05","modified_gmt":"2024-01-09T13:51:05","slug":"twig-and-blade-templates-debugging-2","status":"publish","type":"phpstorm","link":"https:\/\/blog.jetbrains.com\/pt-br\/phpstorm\/2019\/05\/twig-and-blade-templates-debugging-2","title":{"rendered":"Twig and Blade templates debugging"},"content":{"rendered":"<p>In PhpStorm 2019.1, we\u2019ve implemented debugging of Twig and Blade templates.<\/p>\n<p>The problem was that template files are not the files your application runs. They are first compiled into regular PHP and saved to a cache directory, and then the application runs those compiled files.<\/p>\n<p>So before PhpStorm 2019.1, your only option was to identify the compiled file, something like <em>b84f5d6c0f0d85bb9187843.php<\/em>, locate the line you want to place a breakpoint on, and then debug this file instead.<\/p>\n<p>Luckily, things have changed, and you can now debug your template files directly \u2013 there\u2019s no difference between them and regular PHP files in this regard.<\/p>\n<p>To start debugging your templates:<\/p>\n<ol>\n<li>Set up your PHP debugger.<\/li>\n<li>In PhpStorm, go to <em>Settings\/Preferences | Languages &#038; Frameworks | PHP | Debug | Templates<\/em> and specify the directories where your compiled files are stored:\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2019\/04\/phpstorm-templates_directories-1.png\" alt=\"templates_directories\" width=\"800\" height=\"344\" class=\"aligncenter size-full wp-image-14381\" \/><\/li>\n<\/ol>\n<p>In the case of Twig, you also need to set the following configuration options:<br \/>\n<em>debug: true<\/em><br \/>\n<em>auto_reload: true<\/em><\/p>\n<p>In the case of Laravel, just make sure you\u2019re using <a href=\"https:\/\/github.com\/laravel\/framework\/releases\/tag\/v5.8.11\" target=\"_blank\" rel=\"noopener\">version 5.8<\/a> or later, and you\u2019re good to go.<\/p>\n<p>Now, set a breakpoint directly in your template file, just like you would with a PHP file, and begin step debugging!<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2019\/04\/phpstorm-twig_breakpoint_hit-1.png\" alt=\"twig_breakpoint_hit\" width=\"800\" height=\"482\" class=\"aligncenter size-full wp-image-14382\" \/><\/p>\n<p>New to debugging in PhpStorm? Check out the <strong><a href=\"https:\/\/www.jetbrains.com\/phpstorm\/documentation\/debugging\/#quick-start\" target=\"_blank\" rel=\"noopener\">Ultimate Debugging Guide<\/a><\/strong> or this <a href=\"https:\/\/www.youtube.com\/watch?v=bWbXMy_mxxE\" target=\"_blank\" rel=\"noopener\">Quickstart video<\/a> on getting started with <strong><a href=\"https:\/\/www.youtube.com\/watch?v=bWbXMy_mxxE\" target=\"_blank\" rel=\"noopener\">debugging in Docker<\/a><\/strong>.<\/p>\n<p><em>Your JetBrains PhpStorm Team<\/em><br \/>\n<em>The Drive to Develop<\/em><\/p>\n","protected":false},"author":745,"featured_media":21102,"comment_status":"open","ping_status":"open","template":"","categories":[808,907],"tags":[744,2305,263,1112],"cross-post-tag":[],"acf":[],"_links":{"self":[{"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/phpstorm\/21076"}],"collection":[{"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/phpstorm"}],"about":[{"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/types\/phpstorm"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/users\/745"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/comments?post=21076"}],"version-history":[{"count":1,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/phpstorm\/21076\/revisions"}],"predecessor-version":[{"id":431939,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/phpstorm\/21076\/revisions\/431939"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/media\/21102"}],"wp:attachment":[{"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/media?parent=21076"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/categories?post=21076"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/tags?post=21076"},{"taxonomy":"cross-post-tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/cross-post-tag?post=21076"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}