Skip to content

Commit e1dec43

Browse files
authored
Merge pull request #33 from pattern-lab/feature/error-on-uncompiled-pattern
Throwing error on uncompiled templates
2 parents b8f0c98 + 6e16b3d commit e1dec43

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,16 @@ public function __construct($options = array()) {
116116
*/
117117
public function render($options = array()) {
118118

119-
return $this->instance->render($options["pattern"], $options["data"]);
119+
$result = $this->instance->render($options["pattern"], $options["data"]);
120+
// This error handler catches files that didn't render using any of the loaders.
121+
// The most common scenario is when a file's contents get passed to and through `Twig_Loader_String` and
122+
// outputs the raw Twig file contents like `@atoms/buttons/button.twig`.
123+
// @todo Remove this once `Twig_Loader_String` is removed.
124+
if (strpos($result, "@") === 0) {
125+
throw new \Twig_Error_Loader("Twig file not found: " . $result . "\n");
126+
} else {
127+
return $result;
128+
}
120129

121130
}
122131

0 commit comments

Comments
 (0)