better templating
This commit is contained in:
@@ -97,12 +97,14 @@ class Html extends Formatter {
|
||||
);
|
||||
}
|
||||
|
||||
$html = file_get_contents('template.html');
|
||||
$panel = static::template($context, 'panel');
|
||||
echo static::template(array('title' => $context['title'], 'content' => $panel));
|
||||
}
|
||||
|
||||
foreach($context as $k => $v) {
|
||||
$html = str_replace("{{ $k }}", $v, $html);
|
||||
}
|
||||
public static function template(array $context = array(), $template = 'layout') {
|
||||
$html = file_get_contents(sprintf('templates/%s.html', $template));
|
||||
|
||||
echo $html;
|
||||
$patterns = array_map(function($p) { return "{{ $p }}"; }, array_keys($context));
|
||||
return str_replace($patterns, array_values($context), $html);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,14 +30,7 @@
|
||||
</nav>
|
||||
|
||||
<div class="container-fluid">
|
||||
<div class="panel panel-{{ status }}">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">{{ title }}</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
{{ content }}
|
||||
</div>
|
||||
</div>
|
||||
{{ content }}
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
|
||||
8
templates/panel.html
Normal file
8
templates/panel.html
Normal file
@@ -0,0 +1,8 @@
|
||||
<div class="panel panel-{{ status }}">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">{{ title }}</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
{{ content }}
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user