Added templating for css (styles) and other generic files
* Fixed null files was causing error on foreach
This commit is contained in:
parent
2f406745a8
commit
4cf4de2b20
|
@ -9,6 +9,7 @@
|
|||
<script type="application/javascript" src="/js/relativeTime.js"></script>
|
||||
<script type="application/javascript" src="/js/updateLocale.js"></script>
|
||||
-->
|
||||
<?php tpl_styles($styles ?? null) ?>
|
||||
<?php tpl_scripts($scripts ?? null) ?>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -15,19 +15,30 @@ function tpl($ns, $args=[]) {
|
|||
}
|
||||
}
|
||||
|
||||
function tpl_script($script) {
|
||||
function tpl_file($name, $dir, $ext) {
|
||||
$suffix = '';
|
||||
$script = str_replace('.', '/', $script);
|
||||
$name = str_replace('.', '/', $name);
|
||||
if (getenv('env') === DEV)
|
||||
$suffix = '?_='.microtime();
|
||||
echo APP_DIR.'/js/'.$script.'.js'.$suffix;
|
||||
return APP_DIR.'/'.$dir.'/'.$name.'.'.$ext.$suffix;
|
||||
}
|
||||
|
||||
function tpl_script($script) { echo tpl_file($script, 'js', 'js'); }
|
||||
function tpl_scripts($scripts) {
|
||||
if ($scripts === null) $scripts = [];
|
||||
foreach ($scripts as $script) {
|
||||
?><script type="application/javascript" src="<?php tpl_script($script) ?>"></script><?php
|
||||
}
|
||||
}
|
||||
|
||||
function tpl_style($style) { echo tpl_file($style, 'css', 'css'); }
|
||||
function tpl_styles($styles) {
|
||||
if ($styles === null) $styles = [];
|
||||
foreach ($styles as $style) {
|
||||
?><link rel="stylesheet" href="<?php tpl_style($style) ?>"><?php
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function cookie_redirect_app() {
|
||||
// TODO: also check if cookie is valid to redirect
|
||||
|
|
Loading…
Reference in New Issue