Templates and Assets
TemplateLoader
TemplateLoader::show('head', ['title' => 'Product List']); // public/_Template/head.php
TemplateLoader::content(); // execute the page mapped to the URL
TemplateLoader::entryDir('_layout'); // _layout.php in the current URL directory
TemplateLoader::entryRoot('_footer'); // public/_footer.php
The supplied array is passed through extract() and exposed as local variables inside the template.
<!-- public/_Template/head.php -->
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">
<title><?= htmlspecialchars($title ?? _Global::$SITE_TITLE) ?></title>
<?php \_Flexagon\Libs\AssetLoader::printPreloads(' ') ?>
<?php \_Flexagon\Libs\AssetLoader::printStyles(' ') ?>
</head>
<body>
AssetLoader
Collect CSS and JavaScript assets and render them together at the desired location. A version query string can be added for cache invalidation.
use _Flexagon\Libs\AssetLoader;
AssetLoader::setVersion('3.4.13'); // append ?_=3.4.13 to all asset URLs
AssetLoader::setAssetRootPath('/assets/');
AssetLoader::setCss('main.css'); // /assets/css/main.css (includes preload)
AssetLoader::setJs('app.js', isModule: true); // /assets/js/app.js
AssetLoader::setJs('https://cdn.example.com/lib.js'); // external URLs remain unchanged
echo AssetLoader::getImageHtml('logo.png', 120, 40, 'Logo');
echo AssetLoader::getAssetUrl('fonts/pretendard.woff2');
- Relative paths are prefixed with
assetRootPath + dirPath; URLs beginning withhttp://,https://, or//are left unchanged. - Preload hints are rendered separately with
printPreloads(). Place them in<head>while leaving script tags at theprintScripts()location (typically just before</body>) so scripts can be fetched while the document body is being parsed. - Preload hints are not added to absolute URLs because a mismatched
crossoriginsetting may cause the browser to download the resource twice. - Each
print*()method renders one asset type, and the template controls placement:printPreloads()andprintStyles()belong in<head>, whileprintScripts()typically goes just before</body>. - Use
unsetJs('analytics.js')to remove a previously registered script.