Skip to content

Commit ddbf8bc

Browse files
committed
loading tags dynamically
1 parent da83b1f commit ddbf8bc

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/PatternLab/PatternEngine/Twig/TwigUtil.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,38 @@ public static function loadMacros($instance) {
177177

178178
}
179179

180+
/**
181+
* Load tags for the Twig PatternEngine
182+
* @param {Instance} an instance of the twig engine
183+
*
184+
* @return {Instance} an instance of the twig engine
185+
*/
186+
public static function loadTags($instance) {
187+
188+
// load defaults
189+
$tagDir = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_twig-components/tags";
190+
$tagExt = Config::getOption("twigTagExt");
191+
$tagExt = $tagExt ? $tagExt : "tag.twig";
192+
193+
if (is_dir($tagDir)) {
194+
195+
// loop through the tags and instantiate the class...
196+
$finder = new Finder();
197+
$finder->files()->name("*\.".$tagExt)->in($tagDir);
198+
$finder->sortByName();
199+
foreach ($finder as $file) {
200+
include($file->getPathname());
201+
$className = "Project_".$file->getBasename(".".$tagExt)."_TokenParser";
202+
$instance->addTokenParser(new $className());
203+
}
204+
205+
} else {
206+
207+
self::dirNotExist($tagDir);
208+
209+
}
210+
211+
return $instance;
212+
213+
}
180214
}

0 commit comments

Comments
 (0)