Skip to content

Commit fa3fb14

Browse files
authored
Update Hooks.php
1 parent f00180a commit fa3fb14

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

classes/Hooks.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,36 @@ public function addCssFiles($strBuffer, $strTemplate)
120120
$arrF[] = str_replace(TL_ROOT.'/', '', $k);
121121
}
122122

123-
foreach ($arrF as $file) {
124-
123+
foreach ($arrF as $k => $file) {
124+
125125
$dir = dirname($file);
126-
$filePath = $dir.'/css/'.basename($file);
126+
$filename = basename($file);
127+
$filePath = $dir.'/css/'.$filename;
127128
$filePath = str_replace('.less', '.css', $filePath);
128129

129130
if(is_readable(TL_ROOT.'/'.$filePath)) {
130131
$GLOBALS['TL_BODY'][] = \Template::generateStyleTag(\Controller::addStaticUrlTo($filePath), '', false);
131132
} else {
132-
$GLOBALS['TL_BODY'][] = \Template::generateStyleTag(\Controller::addStaticUrlTo($file), '', false);
133+
134+
if(strpos($filename, '.less') !== false) {
135+
136+
$parser = new \Less_Parser();
137+
$parser->parseFile($file, $k);
138+
$css = $parser->getCss();
139+
140+
if(!is_dir(TL_ROOT.'/'.$dir.'/css')) {
141+
mkdir(TL_ROOT.'/'.$dir.'/css', 0755, true);
142+
}
143+
144+
file_put_contents(TL_ROOT.'/'.$filePath, $css);
145+
146+
$GLOBALS['TL_BODY'][] = \Template::generateStyleTag(\Controller::addStaticUrlTo($filePath), '', false);
147+
148+
149+
} else {
150+
$GLOBALS['TL_BODY'][] = \Template::generateStyleTag(\Controller::addStaticUrlTo($file), '', false);
151+
}
152+
133153
}
134154
}
135155

0 commit comments

Comments
 (0)