From 0a005d570be0d963f1f04d1f20a3b3589e80f25d Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Tue, 11 Jan 2022 10:11:09 +0100 Subject: [PATCH] Support multiple additions of the same section content --- application/helpers/html_helper.php | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/application/helpers/html_helper.php b/application/helpers/html_helper.php index 798e4a53..9da0ee36 100644 --- a/application/helpers/html_helper.php +++ b/application/helpers/html_helper.php @@ -28,19 +28,19 @@ if ( ! function_exists('component')) * @param string $component Component template file name. * @param string $attributes HTML attributes for the parent component element. * @param array $params Additional parameters for the component. - * @param bool $return Whether to return the HTML or echo it directly. - * - * @return string Return the HTML if the $return argument is TRUE or NULL. + * @param bool $return Whether to return the HTML or echo it directly. + * + * @return string Return the HTML if the $return argument is TRUE or NULL. */ function component(string $component, string $attributes = '', array $params = [], bool $return = FALSE) { /** @var EA_Controller $CI */ $CI = get_instance(); - + $vars = array_merge($params, [ 'attributes' => $attributes ]); - + return $CI->load->view('components/' . $component, $vars, $return); } } @@ -90,14 +90,14 @@ if ( ! function_exists('section')) if (array_key_exists($name, $layout['sections'])) { - $layout['sections'][$name] = ob_get_clean(); + $layout['sections'][$name][] = ob_get_clean(); config(['layout' => $layout]); return; } - $layout['sections'][$name] = ''; + $layout['sections'][$name] = []; config(['layout' => $layout]); @@ -116,6 +116,16 @@ if ( ! function_exists('slot')) { $layout = config('layout'); - echo $layout['sections'][$name] ?? ''; + $section = $layout['sections'][$name] ?? NULL; + + if ( ! $section) + { + return; + } + + foreach ($section as $content) + { + echo $content; + } } }