Skip to content

Instantly share code, notes, and snippets.

@kunicmarko20
Created August 1, 2017 08:54
Show Gist options
  • Save kunicmarko20/9b986b822e3b3f8f97d93906558d6b54 to your computer and use it in GitHub Desktop.
Save kunicmarko20/9b986b822e3b3f8f97d93906558d6b54 to your computer and use it in GitHub Desktop.
Twig template name in html comments

Twig template name in html comments

This example will add template names in html comments inside of Symfony twig templates.

#app/config/config.yml
# Twig Configuration
twig:
#...
base_template_class: AppBundle\Twig\DebugTemplate
<?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