Use template for HTML

This commit is contained in:
Gilles Crettenand
2015-06-02 09:47:22 +02:00
committed by Gilles Crettenand
parent 34161ba282
commit 2a802ee5e1
2 changed files with 39 additions and 5 deletions

View File

@@ -18,12 +18,14 @@ class Html extends Formatter {
$first = reset($data);
$single = ! is_array($first);
$content = '<table><thead>';
$content = '<table class="table table-striped table-hover"><thead>';
if($single) {
$content .= "<tr><th>Field</th><th>Value</th></tr>";
} else {
$columns = array_keys($first);
$content .= '<tr>';
foreach(array_keys($first) as $k) {
foreach($columns as $k) {
$content .= "<th>$k</th>";
}
$content .= '</tr>';
@@ -36,8 +38,14 @@ class Html extends Formatter {
} else {
foreach($data as $row) {
$content .= '<tr>';
foreach($row as $col) {
$content .= '<td>'.print_r($col, true).'</td>';
foreach($columns as $c) {
$v = print_r(isset($row[$c]) ? $row[$c] : '', true);
$limit = 50;
if(strlen($v) > $limit) {
$v = substr($v, 0, $limit).' [...]';
}
$content .= "<td>$v</td>";
}
$content .= '</tr>';
}
@@ -75,6 +83,17 @@ class Html extends Formatter {
$content = '<h1>Unable to render this</h1>';
}
echo $content;
$html = file_get_contents('template.html');
$context = array(
'title' => 'BSR - WebService',
'content' => $content
);
foreach($context as $k => $v) {
$html = str_replace("{{ $k }}", $v, $html);
}
echo $html;
}
}