Closed corysimmons closed 4 years ago
Attempted to clean it up a little bit. Still not super useful for my needs, but maybe it'll help someone else?
<?php
class Debug_Bar_Timber extends Debug_Bar_Panel {
var $files;
var $datas;
var $filenames;
var $php_files;
function init() {
$this->datas = array();
$this->files = array();
$this->filenames = array();
$this->title( 'Timber' );
add_action( 'wp_ajax_debug_bar_console', array(
$this,
'ajax'
) );
add_action( 'timber_loader_render_file', array(
$this,
'add_file'
) );
add_filter( 'timber_render_file', array(
$this,
'render_file'
) );
add_filter( 'timber_loader_render_data', array(
$this,
'render_data'
) );
add_filter( 'timber_calling_php_file', array(
$this,
'add_php_file'
) );
}
function add_php_file( $php_file ) {
$this->php_files[] = $php_file;
return $php_file;
}
function add_file( $file ) {
$this->files[] = $file;
}
function render_file( $file ) {
$this->filenames[] = $file;
return $file;
}
function render_data( $data ) {
$this->datas[] = $data;
return $data;
}
function prerender() {
$this->set_visible( true );
}
function render() {
$files = $this->filenames;
$datas = $this->datas;
$php_files = $this->php_files;
for ( $i = 0; $i <= count( $files ); $i++ ) {
echo '<h3 style="display:block; font-size:24px; font-weight:bold; font-family:Consolas, mono; color:#111">' . $files[$i] . '</h3>';
if ( isset( $php_files ) && is_array( $php_files ) ) {
echo "<div style='border: 1px solid #ddd; padding: 15px; height: 300px; overflow-y: scroll; margin-bottom: 30px;'>";
foreach ( $php_files as $php_file ) {
echo '<p style="display:block; font-size:12px; line-height: 1.5; font-weight:bold; font-family:Consolas, mono; color:#AAA; margin-bottom: 10px;">Called from <span style="color:#111">' . $php_file . '</span></p>';
}
echo "</div>";
}
echo "<p>Timber found template: <code style='font-family:Consolas, mono'>" . $files[$i] . "</code>. Here's the data that you sent: </p>";
if ( count( $datas ) && isset( $datas[$i] ) ) {
echo '<pre style="background-color:#e2e2e2; font-family: Consolas, monospace, mono; white-space:pre; font-size:10px; height: 300px; overflow-y: scroll;">';
print_r( $datas[$i] );
echo '</pre>';
}
$i++;
}
}
}
This makes it look like:
With scrollable boxes.
@corysimmons is this still an issue?
Sorry, no idea. Haven't used PHP/Twig in a few years. Feel free to close.
Thanks
It's pretty difficult to match up what dumps go with what templates and where they were called from.
Seems like this could be fixed by refactoring the
render()
function a bit.