From 173a440605d836792c33c502d75c9cfc0087264f Mon Sep 17 00:00:00 2001 From: gilbert hutagalung <77769821+gilberthtg@users.noreply.github.com> Date: Wed, 1 Oct 2025 15:57:34 +0700 Subject: [PATCH] feat(view): add default value support for renderSection() This commit extends the View::renderSection() method to allow an optional default value parameter when a section is not found or is empty. - Added a new `$default` argument to renderSection() - If the requested section is missing or empty, the method will return the provided default value instead of an empty string - Preserves existing behavior when `$default` is not set This improvement makes it easier to provide fallback content in layouts without requiring additional wrapper logic in user applications. Example usage: renderSection('form', '

Default form content

') ?> --- system/View/View.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/View/View.php b/system/View/View.php index 184f2528c32c..d963b95595c9 100644 --- a/system/View/View.php +++ b/system/View/View.php @@ -446,10 +446,10 @@ public function endSection() * @param bool $saveData If true, saves data for subsequent calls, * if false, cleans the data after displaying. */ - public function renderSection(string $sectionName, bool $saveData = false): string + public function renderSection(string $sectionName, bool $saveData = false, string $defaultContent= ""): string { if (! isset($this->sections[$sectionName])) { - return ''; + return $defaultContent; } $output = '';