File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
src/PatternLab/PatternEngine/Twig Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -102,6 +102,49 @@ public static function loadFilters($instance) {
102102 return $ instance ;
103103
104104 }
105+
106+ /**
107+ * Load functions for the Twig PatternEngine
108+ * @param {Instance} an instance of the twig engine
109+ *
110+ * @return {Instance} an instance of the twig engine
111+ */
112+ public static function loadFunctions ($ instance ) {
113+
114+ // load defaults
115+ $ functionDir = Config::getOption ("sourceDir " ).DIRECTORY_SEPARATOR ."_twig-components/functions " ;
116+ $ functionExt = Config::getOption ("twigFunctionExt " );
117+ $ functionExt = $ functionExt ? $ functionExt : "function.twig " ;
118+
119+ if (is_dir ($ functionDir )) {
120+
121+ // loop through the function dir...
122+ $ finder = new Finder ();
123+ $ finder ->files ()->name ("*\. " .$ functionExt )->in ($ functionDir );
124+ $ finder ->sortByName ();
125+ foreach ($ finder as $ file ) {
126+
127+ include ($ file ->getPathname ());
128+
129+ // $function should be defined in the included file
130+ if (isset ($ function )) {
131+ $ instance ->addFunction ($ function );
132+ unset($ function );
133+ }
134+
135+ }
136+
137+ } else {
138+
139+ self ::dirNotExist ($ functionDir );
140+
141+ }
142+
143+ return $ instance ;
144+
145+ }
146+
147+ /**
105148 * Load macros for the Twig PatternEngine
106149 * @param {Instance} an instance of the twig engine
107150 * @param {String} description of the loader type for the error
You can’t perform that action at this time.
0 commit comments