This commit is contained in:
2025-11-21 01:56:02 +01:00
parent 1f77464e1f
commit 732733b9da
11 changed files with 195 additions and 11 deletions

View File

@@ -1,4 +1,72 @@
<?php
<?php
$GLOBALS['page_header_scripts'] = $GLOBALS['page_header_scripts'] ?? [];
$GLOBALS['page_footer_scripts'] = $GLOBALS['page_footer_scripts'] ?? [];
$GLOBALS['page_styles'] = $GLOBALS['page_styles'] ?? [];
/**
* Script registrieren
*
* @param string $src Pfad zur Datei, z. B. '/assets/js/auth.js'
* @param string $pos 'header' oder 'footer'
* @param bool $defer standard true
* @param bool $async standard false
* @param string $type z. B. 'module'
* @param string|null $version null = nutze ASSET_VERSION (falls definiert),
* '' = kein ?v=,
* 'xyz'= erzwinge diese Version
*/
function tpl_add_script(
string $src,
string $pos = 'footer',
bool $defer = true,
bool $async = false,
string $type = '',
?string $version = null
): void {
// Standard-Verhalten: falls Version nicht explizit gesetzt → globale ASSET_VERSION verwenden
if ($version === null && defined('ASSET_VERSION')) {
$version = ASSET_VERSION;
}
$data = [
'src' => $src,
'defer' => $defer,
'async' => $async,
'type' => $type,
'version' => $version, // kann null, '' oder string sein
];
if ($pos === 'header') {
$GLOBALS['page_header_scripts'][] = $data;
} else {
$GLOBALS['page_footer_scripts'][] = $data;
}
}
/**
* CSS registrieren
*
* @param string $href Pfad zur CSS
* @param string $pos 'header' oder 'footer'
* @param string|null $version gleiche Logik wie bei Scripts
*/
function tpl_add_style(string $href, string $pos = 'header', ?string $version = null): void
{
if ($version === null && defined('ASSET_VERSION')) {
$version = ASSET_VERSION;
}
$GLOBALS['page_styles'][] = [
'href' => $href,
'pos' => $pos,
'version' => $version,
];
}
/**
* Templating Loader
*