From: Ben Sherratt Date: Mon, 29 Dec 2025 16:27:33 +0000 (+0000) Subject: Added template fallback support X-Git-Url: https://git.bts.cx/garden.git/commitdiff_plain/e5a40d56a7e31209bae79ffddeda5f70749f6d2f?hp=2812e275ef0f68ae484ec50fd954dd88225a2532 Added template fallback support --- diff --git a/garden.php b/garden.php index 99cb012..6035ee8 100644 --- a/garden.php +++ b/garden.php @@ -260,7 +260,11 @@ function garden_template_render($name, $variables = null) { $output = ''; while ($name != null) { $path = garden_path(GARDEN_TEMPLATE_DIR, $name . '.php'); - + + if (file_exists($path) == false) { + $path = garden_path(GARDEN_FALLBACK_TEMPLATE_DIR, $name . '.php'); + } + $base_template = null; $base_template_variables = null; @@ -312,8 +316,6 @@ function garden_site_url(...$url_segments) { return GARDEN_SITE_BASE_URL . garden_url(...$url_segments); } - - /////////////////////////////////////////////////////////////////////////////// // Images /////////////////////////////////////////////////////////////////////////////// @@ -605,6 +607,8 @@ function garden() { assert(extension_loaded('imagick'), 'Needs Imagick'); assert($argc >= 2, 'Please provide configuration file'); +define('GARDEN_FALLBACK_TEMPLATE_DIR', garden_path(__DIR__, 'templates')); + // First parameter needs to be the configuration php $config_file = $argv[1]; diff --git a/templates/base.php b/templates/base.php index 2961a4b..5a6a743 100644 --- a/templates/base.php +++ b/templates/base.php @@ -13,7 +13,7 @@ - +