From 538ded7d697cd3d69565a81d2057a55b6b89f7f7 Mon Sep 17 00:00:00 2001 From: alextselegidis Date: Thu, 11 Nov 2021 09:00:48 +0100 Subject: [PATCH] Added new component helper file --- application/helpers/component_helper.php | 45 ++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 application/helpers/component_helper.php diff --git a/application/helpers/component_helper.php b/application/helpers/component_helper.php new file mode 100644 index 00000000..fae6c50d --- /dev/null +++ b/application/helpers/component_helper.php @@ -0,0 +1,45 @@ + + * @copyright Copyright (c) 2013 - 2020, Alex Tselegidis + * @license http://opensource.org/licenses/GPL-3.0 - GPLv3 + * @link http://easyappointments.org + * @since v1.4.0 + * ---------------------------------------------------------------------------- */ + +if ( ! function_exists('component')) +{ + /** + * Render a component from the "views/components/*.php" directory. + * + * Use this helper function to easily include components into your HTML markup. + * + * Any loaded template variables will also be available at the component template, but you may also specify + * additional values by adding values to the $params parameter. + * + * Example: + * + * echo component('timezones_dropdown', 'class"form-control"'); + * + * @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. + * + * @return string + */ + function component(string $component, string $attributes = '', array $params = []): string + { + /** @var EA_Controller $CI */ + $CI = &get_instance(); + + $vars = array_merge($params, [ + 'attributes' => $attributes + ]); + + return $CI->load->view('components/' . $component, $vars, TRUE); + } +}