diff --git a/modules/cms/classes/Controller.php b/modules/cms/classes/Controller.php index ff0b8cd31..a6f82b257 100644 --- a/modules/cms/classes/Controller.php +++ b/modules/cms/classes/Controller.php @@ -14,7 +14,8 @@ use Exception; use Twig_Environment; use Controller as BaseController; use Cms\Twig\Loader as TwigLoader; -use Cms\Twig\Extension as TwigExtension; +use Cms\Twig\Extension as CmsTwigExtension; +use System\Twig\Extension as SystemTwigExtension; use Cms\Classes\FileHelper as CmsFileHelper; use System\Classes\ErrorHandler; use October\Rain\Support\Markdown; @@ -229,7 +230,8 @@ class Controller extends BaseController $options['cache'] = storage_path().'/twig'; $this->twig = new Twig_Environment($this->loader, $options); - $this->twig->addExtension(new TwigExtension($this)); + $this->twig->addExtension(new CmsTwigExtension($this)); + $this->twig->addExtension(new SystemTwigExtension); } /** diff --git a/modules/cms/twig/Extension.php b/modules/cms/twig/Extension.php index 768940586..c91caed9d 100644 --- a/modules/cms/twig/Extension.php +++ b/modules/cms/twig/Extension.php @@ -86,7 +86,6 @@ class Extension extends Twig_Extension public function getFilters() { $filters = [ - new Twig_SimpleFilter('app', [$this, 'appFilter'], ['is_safe' => ['html']]), new Twig_SimpleFilter('page', [$this, 'pageFilter'], ['is_safe' => ['html']]), new Twig_SimpleFilter('theme', [$this, 'themeFilter'], ['is_safe' => ['html']]), ]; @@ -211,16 +210,6 @@ class Extension extends Twig_Extension return $this->controller->themeUrl($url); } - /** - * Converts supplied URL to one relative to the website root. - * @param mixed $url Specifies the application-relative URL - * @return string - */ - public function appFilter($url) - { - return URL::to($url); - } - /** * Looks up the URL for a supplied page and returns it relative to the website root. * @param mixed $name Specifies the Cms Page file name. diff --git a/modules/system/ServiceProvider.php b/modules/system/ServiceProvider.php index a1aae7bfd..620ef7c2b 100644 --- a/modules/system/ServiceProvider.php +++ b/modules/system/ServiceProvider.php @@ -13,6 +13,7 @@ use System\Classes\PluginManager; use System\Classes\SettingsManager; use System\Twig\Engine as TwigEngine; use System\Twig\Loader as TwigLoader; +use System\Twig\Extension as TwigExtension; use System\Models\EmailSettings; use System\Models\EmailTemplate; use Backend\Classes\WidgetManager; @@ -74,7 +75,9 @@ class ServiceProvider extends ModuleServiceProvider * Register basic twig */ App::bindShared('twig', function($app) { - return new Twig_Environment(new TwigLoader(), ['auto_reload' => true]); + $twig = new Twig_Environment(new TwigLoader(), ['auto_reload' => true]); + $twig->addExtension(new TwigExtension); + return $twig; }); /* diff --git a/modules/system/twig/Extension.php b/modules/system/twig/Extension.php new file mode 100644 index 000000000..7b413c76d --- /dev/null +++ b/modules/system/twig/Extension.php @@ -0,0 +1,76 @@ + ['html']]), + ]; + + return $filters; + } + + /** + * Returns a list of token parsers this extensions provides. + * + * @return array An array of token parsers + */ + public function getTokenParsers() + { + return []; + } + + /** + * Converts supplied URL to one relative to the website root. + * @param mixed $url Specifies the application-relative URL + * @return string + */ + public function appFilter($url) + { + return URL::to($url); + } +} \ No newline at end of file