This example will add template names in html comments inside of Symfony twig templates.
Created
August 1, 2017 08:54
-
-
Save kunicmarko20/9b986b822e3b3f8f97d93906558d6b54 to your computer and use it in GitHub Desktop.
Twig template name in html comments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#app/config/config.yml | |
# Twig Configuration | |
twig: | |
#... | |
base_template_class: AppBundle\Twig\DebugTemplate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace AppBundle\Twig; | |
abstract class DebugTemplate extends \Twig_Template { | |
public function display(array $context, array $blocks = array()) | |
{ | |
echo '<!-- START: ' . $this->getTemplateName() . ' -->'; | |
parent::display($context, $blocks); | |
echo '<!-- END: ' . $this->getTemplateName() . ' -->'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment