From c70ae88a2a89404f008436e9bc17551459b5f6dc Mon Sep 17 00:00:00 2001 From: Anonymous Contributor Date: Sat, 2 Sep 2023 15:33:21 +0200 Subject: [PATCH] Add dirFiles Twig function --- four-creative.php | 11 ++++++++++- php/DirFilesExtension.php | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 php/DirFilesExtension.php diff --git a/four-creative.php b/four-creative.php index 472f033..f651fbd 100644 --- a/four-creative.php +++ b/four-creative.php @@ -5,5 +5,14 @@ use Grav\Common\Theme; class FourCreative extends Theme { - // Access plugin events in this class + public static function getSubscribedEvents() + { + return ['onTwigExtensions' => ['onTwigExtensions', 0]]; + } + + public function onTwigExtensions() + { + require_once __DIR__.DIRECTORY_SEPARATOR.'php'.DIRECTORY_SEPARATOR.'DirFilesExtension.php'; + $this->grav['twig']->twig->addExtension(new DirFilesExtension()); + } } diff --git a/php/DirFilesExtension.php b/php/DirFilesExtension.php new file mode 100644 index 0000000..432cfe8 --- /dev/null +++ b/php/DirFilesExtension.php @@ -0,0 +1,35 @@ +