From 9bdb91a23e79f655fb5a05f8800b997dcc7316e2 Mon Sep 17 00:00:00 2001 From: Robert Date: Sun, 27 Jul 2025 16:02:11 -0400 Subject: [PATCH] init 7 --- .gitignore | 2 ++ protected/src/composer.json | 6 ++++++ protected/src/configs/on_view_mode.php | 2 +- protected/src/controllers/app/home_ctrl.php | 24 ++++++++++++++++----- protected/src/services/on_liquid.php | 15 +++++++++++++ protected/src/services/on_twig.php | 15 +++++++++++++ protected/src/views/liquid/app/liquid.tpl | 14 ++++++++++++ protected/src/views/twig/app/test.twig | 11 ++++++++++ 8 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 protected/src/composer.json create mode 100644 protected/src/services/on_liquid.php create mode 100644 protected/src/services/on_twig.php create mode 100644 protected/src/views/liquid/app/liquid.tpl create mode 100644 protected/src/views/twig/app/test.twig diff --git a/.gitignore b/.gitignore index 57c9aaa..e0c5635 100644 --- a/.gitignore +++ b/.gitignore @@ -2,8 +2,10 @@ protected/FWCodeHydrater protected/src/secret_php_files protected/src/aes protected/src/aeskeys.php +protected/src/vendor protected/keydata protected/runtime protected/logs +protected/src/composer.lock *.swp *.log diff --git a/protected/src/composer.json b/protected/src/composer.json new file mode 100644 index 0000000..e07dc5d --- /dev/null +++ b/protected/src/composer.json @@ -0,0 +1,6 @@ +{ + "require": { + "twig/twig": "^3.0", + "liquid/liquid": "^1.4" + } +} diff --git a/protected/src/configs/on_view_mode.php b/protected/src/configs/on_view_mode.php index 8840b9d..b1b2b5e 100644 --- a/protected/src/configs/on_view_mode.php +++ b/protected/src/configs/on_view_mode.php @@ -5,5 +5,5 @@ declare(strict_types=1); use CodeHydrater\bootstrap\configure as Config; Config::set('view_mode', array( - 'default_paths' => array('json', 'common', 'flexbox', 'default') + 'default_paths' => array('json', 'common', 'flexbox', 'default', 'twig', 'liquid') )); \ No newline at end of file diff --git a/protected/src/controllers/app/home_ctrl.php b/protected/src/controllers/app/home_ctrl.php index 2713c65..5c4f1f7 100644 --- a/protected/src/controllers/app/home_ctrl.php +++ b/protected/src/controllers/app/home_ctrl.php @@ -9,6 +9,9 @@ declare(strict_types = 1); */ namespace Project\controllers\app; +use CodeHydrater\enums\view_type as ViewType; +use CodeHydrater\bootstrap\registry as Reg; + /** * Description of home_ctrl * @@ -19,17 +22,28 @@ class home_ctrl { public function index() { $html = new \CodeHydrater\html_document(); $html->set_author("Robert Strutts, plus ME!"); - + $view = new \CodeHydrater\view(); $view->set('html', $html); $view->set_template('main'); - $view->include("app/header"); - $view->include("app/footer"); - $view->render($this, "app/home_index"); + $view->include("app/header", ViewType::PHP); + $view->include("app/footer", ViewType::PHP); + $view->render($this, "app/home_index", ViewType::PHP); } public function name_demo() { - echo "OLD DEMO Page...!"; + $view = new \CodeHydrater\view(); + $view->set('twig_data', ['name' => "John Doe"]); + $view->render($this, "app/test", ViewType::TWIG); + } + + public function liquid() { + $view = new \CodeHydrater\view(); + $view->set('template_assigns', [ + 'name' => "James Smith", + 'date' => date('Y-m-d') + ]); + $view->render($this, "app/liquid", ViewType::LIQUID); } public function extra() { diff --git a/protected/src/services/on_liquid.php b/protected/src/services/on_liquid.php new file mode 100644 index 0000000..26605d0 --- /dev/null +++ b/protected/src/services/on_liquid.php @@ -0,0 +1,15 @@ + + * @copyright (c) 2025, Robert Strutts + * @license MIT + */ + +use CodeHydrater\bootstrap\registry as Reg; + +Reg::get('di')->register('liquid', function() { + return new \CodeHydrater\services\liquid_templates(); +}); diff --git a/protected/src/services/on_twig.php b/protected/src/services/on_twig.php new file mode 100644 index 0000000..a550f11 --- /dev/null +++ b/protected/src/services/on_twig.php @@ -0,0 +1,15 @@ + + * @copyright (c) 2025, Robert Strutts + * @license MIT + */ + +use CodeHydrater\bootstrap\registry as Reg; + +Reg::get('di')->register('twig', function() { + return \CodeHydrater\services\twig::init(); +}); diff --git a/protected/src/views/liquid/app/liquid.tpl b/protected/src/views/liquid/app/liquid.tpl new file mode 100644 index 0000000..a8a2573 --- /dev/null +++ b/protected/src/views/liquid/app/liquid.tpl @@ -0,0 +1,14 @@ + + + + Liquid Example + + +

Hello, {{ name }}!

+

Today is {{ date }}.

+ + {% if name.size > 0 %} +

Your name has {{ name.size }} characters.

+ {% endif %} + + \ No newline at end of file diff --git a/protected/src/views/twig/app/test.twig b/protected/src/views/twig/app/test.twig new file mode 100644 index 0000000..5b528fb --- /dev/null +++ b/protected/src/views/twig/app/test.twig @@ -0,0 +1,11 @@ + + + + Twig Example + + +

Hello, {{ name }}!

+

Welcome to our website.

+

Twig Demo Page.

+ +