diff options
| author | Savetheinternet <savetheinternet@tinyboard.org> | 2011-11-16 16:01:02 +1100 |
|---|---|---|
| committer | Savetheinternet <savetheinternet@tinyboard.org> | 2011-11-16 16:01:02 +1100 |
| commit | 27dde88e15d9b978197653b4daa1264b25105660 (patch) | |
| tree | cc9b7050b1c5ebf964b9ce02558b9835e41bdc90 /inc | |
| parent | 8c97d15424e810fceba7688646c9c06ce55c0a58 (diff) | |
Added config option to automatically remove unnecessary whitespace when compiling HTML files from templates
Diffstat (limited to 'inc')
| -rw-r--r-- | inc/config.php | 3 | ||||
| -rw-r--r-- | inc/template.php | 10 |
2 files changed, 11 insertions, 2 deletions
diff --git a/inc/config.php b/inc/config.php index 4fc6f40f..0798cba9 100644 --- a/inc/config.php +++ b/inc/config.php @@ -494,6 +494,9 @@ // 'AnotherName' => 'url') //); + // Automatically remove unnecessary whitespace when compiling HTML files from templates. + $config['minify_html'] = false; + /* * ==================== * Video embedding diff --git a/inc/template.php b/inc/template.php index 39d30207..9c61ae15 100644 --- a/inc/template.php +++ b/inc/template.php @@ -28,7 +28,7 @@ unset($debug['start']);
}
- $options['body'] .= '<h3>Debug</h3><pre style="white-space: pre-wrap;font-size: 10px;">' . print_r($debug, true) . '</pre><hr/>';
+ $options['body'] .= '<h3>Debug</h3><pre style="white-space: pre-wrap;font-size: 10px;">' . str_replace("\n", '<br/>', print_r($debug, true)) . '</pre><hr/>';
}
$loader->setPaths($config['dir']['template']);
@@ -43,7 +43,13 @@ // Read the template file
if(@file_get_contents("{$config['dir']['template']}/${templateFile}")) {
- return $twig->render($templateFile, $options);
+ $body = $twig->render($templateFile, $options);
+
+ if($config['minify_html']) {
+ $body = trim(preg_replace("/[\t\r\n]/", '', $body));
+ }
+
+ return $body;
} else {
throw new Exception("Template file '${templateFile}' does not exist or is empty in '{$config['dir']['template']}'!");
}
|
