Skip to content

Commit

Permalink
add support to mustache {{}} in oour blade
Browse files Browse the repository at this point in the history
  • Loading branch information
abdslam01 committed Sep 6, 2021
1 parent 944eeab commit 1f41d83
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions View.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,24 @@
/**
* View
*/
class View {
class View {
/**
* compileView
*
* @param mixed $path_to_views
* @param mixed $params
* @return void
*/
public static function compileView(string $path_to_views, array $params){
$content = file_get_contents($path_to_views);

// change {{$var}} => <?=$var?\> # yeah, you spelled it write
$content = preg_replace("{{{([^\}]*)}}}", "<?=$1?>", $content);

try{
$final_path_to_views = str_replace("views", "cache", $path_to_views);
$file = fopen($final_path_to_views, "w+");
fwrite($file, file_get_contents($path_to_views));
fwrite($file, $content);
fclose($file);

extract($params);
Expand Down

0 comments on commit 1f41d83

Please sign in to comment.