From 2ef6e512dfc04fc14b89b49150de07a8dfb295bf Mon Sep 17 00:00:00 2001 From: Daniel Stainback Date: Sat, 31 Oct 2015 12:23:24 -0400 Subject: [PATCH] Add the ability for plugins to create custom Twig functions --- src/Providers/Theme.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Providers/Theme.php b/src/Providers/Theme.php index 67d280c..dca70b4 100644 --- a/src/Providers/Theme.php +++ b/src/Providers/Theme.php @@ -37,11 +37,16 @@ public function custom($name, $data) $this->customData[$name] = $data; if (method_exists($this, 'custom_' . $name)) { - $function = new \Twig_SimpleFunction($name, [$this, 'custom_' . $name], ['is_safe' => ['html']]); - $this->theme->addFunction($function); + $this->addFunction($name, $this); } } + public function addFunction($name, $obj) + { + $function = new \Twig_SimpleFunction($name, [$obj, 'custom_' . $name], ['is_safe' => ['html']]); + $this->theme->addFunction($function); + } + public function custom_baun_nav() { $data = $this->customData['baun_nav'];