@@ -116,7 +116,7 @@ public function __construct()
116116 {
117117 $ kirby = Kirby::instance ();
118118 $ this ->debug = $ kirby ->get ('option ' , 'debug ' );
119- $ this ->templateDir = $ kirby ->roots ()->templates ();
119+ $ this ->templateDir = $ this -> normalizePath ( $ kirby ->roots ()->templates () );
120120
121121 // Get environment & user config
122122 $ options = [
@@ -128,9 +128,9 @@ public function __construct()
128128 ],
129129 'namespace ' => [
130130 'templates ' => $ this ->templateDir ,
131- 'snippets ' => $ kirby ->roots ->snippets (),
132- 'plugins ' => $ kirby ->roots ->plugins (),
133- 'assets ' => $ kirby ->roots ->assets ()
131+ 'snippets ' => $ this -> normalizePath ( $ kirby ->roots ->snippets () ),
132+ 'plugins ' => $ this -> normalizePath ( $ kirby ->roots ->plugins () ),
133+ 'assets ' => $ this -> normalizePath ( $ kirby ->roots ->assets () )
134134 ],
135135 'function ' => $ this ->cleanNames (array_merge (
136136 $ this ->defaultFunctions ,
@@ -205,8 +205,11 @@ public function renderPath($filePath='', $tplData=[], $return=true, $isPage=fals
205205 {
206206 // Remove the start of the templates path, since Twig asks
207207 // for a path starting from one of the registered directories.
208- $ path = ltrim (str_replace ($ this ->templateDir , '' ,
209- preg_replace ('#[ \\\/]+# ' , '/ ' , $ filePath )), '/ ' );
208+ $ path = $ this ->normalizePath ($ filePath );
209+ $ prefix = $ this ->templateDir . '/ ' ;
210+ if (strpos ($ path , $ prefix ) === 0 ) {
211+ $ path = substr ($ path , strlen ($ prefix ));
212+ }
210213
211214 try {
212215 $ content = $ this ->twig ->render ($ path , $ tplData );
@@ -348,6 +351,15 @@ private function getSourceExcerpt($source='', $line=1, $plus=1, $format=false)
348351 return implode ("\n" , $ excerpt );
349352 }
350353
354+ /**
355+ * Normalize file paths, especially for Windows slashes
356+ */
357+ private function normalizePath ($ path )
358+ {
359+ $ clean = trim (preg_replace ('#[ \\\/]+# ' , '/ ' , $ path ));
360+ return rtrim ($ clean , '/ ' );
361+ }
362+
351363 /**
352364 * Clean up function names for use in Twig templates
353365 * Returns ['twig name' => 'callable name']
0 commit comments