File: /home/xedaptot/be.naniguide.com/app/Library/BuilderJSHelper.php
<?php
namespace App\Library;
class BuilderJSHelper
{
/**
* Read all template HTML files from a theme directory and return as an associative array.
* Keys are template names (e.g. "Page", "Block"), values are the raw HTML content.
* This eliminates the need for the browser to fetch templates one by one at runtime.
*
* @param string $theme Theme name (e.g. "default")
* @return array<string, string> Template name => HTML content
*/
public static function loadTemplates(string $theme = 'default'): array
{
$themePath = resource_path('themes/' . $theme);
$indexFile = $themePath . '/index.json';
if (!file_exists($indexFile)) {
return [];
}
$configData = json_decode(file_get_contents($indexFile));
$allNames = array_merge($configData->pages ?? [], $configData->templates ?? []);
$templates = [];
foreach ($allNames as $name) {
$file = $themePath . '/' . $name . '.template.html';
if (file_exists($file)) {
$templates[$name] = file_get_contents($file);
}
}
return $templates;
}
}