File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
src/PatternLab/PatternEngine/Twig Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,45 @@ public static function loadDebug($instance) {
6363 }
6464
6565 /**
66+ * Load filters for the Twig PatternEngine
67+ * @param {Instance} an instance of the twig engine
68+ *
69+ * @return {Instance} an instance of the twig engine
70+ */
71+ public static function loadFilters ($ instance ) {
72+
73+ // load defaults
74+ $ filterDir = Config::getOption ("sourceDir " ).DIRECTORY_SEPARATOR ."_twig-components/filters " ;
75+ $ filterExt = Config::getOption ("twigFilterExt " );
76+ $ filterExt = $ filterExt ? $ filterExt : "filter.twig " ;
77+
78+ if (is_dir ($ filterDir )) {
79+
80+ // loop through the filter dir...
81+ $ finder = new Finder ();
82+ $ finder ->files ()->name ("*\. " .$ filterExt )->in ($ filterDir );
83+ $ finder ->sortByName ();
84+ foreach ($ finder as $ file ) {
85+
86+ include ($ file ->getPathname ());
87+
88+ // $filter should be defined in the included file
89+ if (isset ($ filter )) {
90+ $ instance ->addFilter ($ filter );
91+ unset($ filter );
92+ }
93+
94+ }
95+
96+ } else {
97+
98+ self ::dirNotExist ($ filterDir );
99+
100+ }
101+
102+ return $ instance ;
103+
104+ }
66105 * Load macros for the Twig PatternEngine
67106 * @param {Instance} an instance of the twig engine
68107 * @param {String} description of the loader type for the error
You can’t perform that action at this time.
0 commit comments