From bb0ee34082e717179aa4821673c5e56077509751 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 22 Oct 2014 21:14:11 -0600 Subject: [PATCH] Tentatively added twig panel to debugbar - currently has issues with "processpage" twig calls used by modular --- system/config/system.yaml | 1 + system/src/Grav/Common/Grav.php | 4 +++- system/src/Grav/Common/Twig.php | 15 ++++++++++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/system/config/system.yaml b/system/config/system.yaml index 27714836f..f2011c695 100644 --- a/system/config/system.yaml +++ b/system/config/system.yaml @@ -42,5 +42,6 @@ assets: # Configuration for Assets Manager (JS, C debugger: enabled: false # Enable Grav debugger and following settings + twig: true # Enable debugging of Twig templates shutdown: close_connection: true # Close the connection before calling onShutdown(). false for debugging diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index 2d2d61282..8f24a4593 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -186,7 +186,7 @@ class Grav extends Container } $this['assets']->init(); - $debugger->addAssets(); + $this->fireEvent('onAssetsInitialized'); $debugger->startTimer('twig', 'Twig'); @@ -201,6 +201,7 @@ class Grav extends Container $this->fireEvent('onPageInitialized'); + $debugger->addAssets(); // Process whole page as required $debugger->startTimer('render', 'Render'); @@ -208,6 +209,7 @@ class Grav extends Container $this->fireEvent('onOutputGenerated'); $debugger->stopTimer('render'); + // Set the header type $this->header(); echo $this->output; diff --git a/system/src/Grav/Common/Twig.php b/system/src/Grav/Common/Twig.php index d42ee3bbe..636e9b578 100644 --- a/system/src/Grav/Common/Twig.php +++ b/system/src/Grav/Common/Twig.php @@ -70,6 +70,7 @@ class Twig $config = $this->grav['config']; /** @var UniformResourceLocator $locator */ $locator = $this->grav['locator']; + $debugger = $this->grav['debugger']; $this->twig_paths = $locator->findResources('theme://templates'); $this->grav->fireEvent('onTwigTemplatePaths'); @@ -84,6 +85,11 @@ class Twig } $this->twig = new \Twig_Environment($loader_chain, $params); + if ($debugger->enabled() && $config->get('system.debugger.twig')) { + $this->twig = new \DebugBar\Bridge\Twig\TraceableTwigEnvironment($this->twig); + $collector = new \DebugBar\Bridge\Twig\TwigCollector($this->twig); + $debugger->addCollector($collector); + } $this->grav->fireEvent('onTwigInitialized'); // set default date format if set in config @@ -95,6 +101,8 @@ class Twig $this->twig->addExtension(new \Twig_Extension_Debug()); } $this->twig->addExtension(new TwigExtension()); + + $this->grav->fireEvent('onTwigExtensions'); $baseUrlAbsolute = $config->get('system.base_url_absolute'); @@ -117,7 +125,6 @@ class Twig 'taxonomy' => $this->grav['taxonomy'], 'browser' => $this->grav['browser'], ); - } } @@ -170,15 +177,17 @@ class Twig $twig_vars['media'] = $item->media(); $twig_vars['header'] = $item->header(); + $local_twig = clone($this->twig); + // Get Twig template layout if ($item->modularTwig()) { $twig_vars['content'] = $content; $template = $item->template() . TEMPLATE_EXT; - $output = $this->twig->render($template, $twig_vars); + $output = $local_twig->render($template, $twig_vars); } else { $name = '@Page:' . $item->path(); $this->setTemplate($name, $content); - $output = $this->twig->render($name, $twig_vars); + $output = $local_twig->render($name, $twig_vars); } return $output;