mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 08:09:18 +02:00
- Created templates/partials/form/_licence.php (shared HTML, no auth logic)
- Created templates/partials/form/_format-website.php (shared HTML, no auth logic)
- Created src/FragmentRenderer.php helper for clean fragment rendering
- Created public/{admin,partage}/fragments/ subdirectories
- Created thin fragment endpoint files: auth guard + data fetch + render template
- Updated all hx-post references in templates to new fragments/ paths
- Updated partage/index.php routing for new fragments subdirectory
- Kept old fragment files as thin delegates for backward compat
- Updated nginx config: added PHP handler in /partage/ location block
46 lines
1.4 KiB
PHP
46 lines
1.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Lightweight HTMX fragment renderer.
|
|
*
|
|
* Renders a shared template partial without wrapping it in full-page layout
|
|
* (no <html>, <head>, <body>, header, or footer).
|
|
*
|
|
* Usage:
|
|
*
|
|
* // public/admin/fragments/licence.php
|
|
* AdminAuth::requireLogin();
|
|
* FragmentRenderer::render('form/_licence', [
|
|
* 'accessTypeId' => $_POST['access_type_id'] ?? '',
|
|
* 'licenseId' => $_POST['license_id'] ?? '',
|
|
* 'licenseTypes' => Database::getInstance()->getAllLicenseTypes(),
|
|
* 'cc2r' => !empty($_POST['cc2r']),
|
|
* 'wantLicense' => !empty($_POST['want_license']),
|
|
* 'adminMode' => true,
|
|
* 'hxPost' => '/admin/fragments/licence.php',
|
|
* ]);
|
|
*
|
|
* The template receives all keys in $data as variables via extract().
|
|
*/
|
|
class FragmentRenderer
|
|
{
|
|
/**
|
|
* Render a template partial for an HTMX fragment response.
|
|
*
|
|
* @param string $template Path relative to APP_ROOT/templates/partials/ (without .php extension)
|
|
* @param array $data Variables to extract into template scope
|
|
*/
|
|
public static function render(string $template, array $data = []): void
|
|
{
|
|
// Prevent output buffering from any wrapping layout
|
|
if (ob_get_level() === 0) {
|
|
ob_start();
|
|
}
|
|
|
|
extract($data, EXTR_SKIP);
|
|
require APP_ROOT . '/templates/partials/' . $template . '.php';
|
|
|
|
ob_end_flush();
|
|
}
|
|
}
|