@@ -26,20 +26,46 @@ class PatternLoader extends Loader {
2626 */
2727 public function __construct ($ options = array ()) {
2828
29- // set-up the loader
29+ // set-up default vars
3030 $ twigDebug = Config::getOption ("twigDebug " );
31- $ patternSourceDir = Config::getOption ("patternSourceDir " );
32- $ macroPath = Config::getOption ("sourceDir " ).DIRECTORY_SEPARATOR ."_macros " ;
33- $ patternPartialLoader = new Twig_Loader_PatternPartialLoader ($ patternSourceDir ,array ("patternPaths " => $ options ["patternPaths " ]));
34- $ patternStringLoader = new \Twig_Loader_String ();
35- $ macroLoader = new \Twig_Loader_Filesystem (array ($ macroPath ));
36- $ twigLoader = new \Twig_Loader_Chain (array ($ patternPartialLoader , $ macroLoader , $ patternStringLoader ));
31+
32+ // set-up the loader list
33+ $ loaders = array ();
34+ $ filesystemLoaderPaths = array ();
35+ $ loaders [] = new Twig_Loader_PatternPartialLoader (Config::getOption ("patternSourceDir " ),array ("patternPaths " => $ options ["patternPaths " ]));
36+
37+
38+ // see if source/_macros exists
39+ $ macrosPath = Config::getOption ("sourceDir " ).DIRECTORY_SEPARATOR ."_macros " ;
40+ if (is_dir ($ macrosPath )) {
41+ $ filesystemLoaderPaths [] = $ macrosPath ;
42+ }
43+
44+ // see if source/_layouts exists. if so add it to be searchable
45+ $ layoutsPath = Config::getOption ("sourceDir " ).DIRECTORY_SEPARATOR ."_layouts " ;
46+ if (is_dir ($ layoutsPath )) {
47+ $ filesystemLoaderPaths [] = $ layoutsPath ;
48+ }
49+
50+ // add the paths to the filesystem loader if the paths existed
51+ if (count ($ filesystemLoaderPaths ) > 0 ) {
52+ $ loaders [] = new \Twig_Loader_Filesystem ($ filesystemLoaderPaths );
53+ }
54+
55+ $ loaders [] = new \Twig_Loader_String ();
56+
57+ // set-up Twig
58+ $ twigLoader = new \Twig_Loader_Chain ($ loaders );
3759 $ this ->instance = new \Twig_Environment ($ twigLoader , array ("debug " => $ twigDebug ));
3860
39- // customize the loader
61+ // customize Twig
62+ $ this ->instance = TwigUtil::loadFilters ($ this ->instance );
63+ $ this ->instance = TwigUtil::loadFunctions ($ this ->instance );
64+ $ this ->instance = TwigUtil::loadTags ($ this ->instance );
65+ $ this ->instance = TwigUtil::loadTests ($ this ->instance );
4066 $ this ->instance = TwigUtil::loadDateFormats ($ this ->instance );
4167 $ this ->instance = TwigUtil::loadDebug ($ this ->instance );
42- $ this ->instance = TwigUtil::loadMacros ($ this ->instance , " pattern " );
68+ $ this ->instance = TwigUtil::loadMacros ($ this ->instance );
4369
4470 }
4571
0 commit comments