Last active
May 8, 2017 19:54
-
-
Save luckyshot/5395602 to your computer and use it in GitHub Desktop.
Simple Templating Engine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function view($filename = 'home') { | |
// Default values for every View | |
$data = array( | |
"app_title" => $this->app_title, | |
"app_tagline" => $this->app_tagline, | |
"app_url" => $this->app_url, | |
"app_version" => $this->app_version, | |
"user_name" => $this->user_name, | |
); | |
// Read the file | |
if (file_exists('views/'.$filename.'.php')) { | |
$file = file_get_contents('views/'.$filename.'.php'); | |
}else{ | |
$file = file_get_contents('views/home.php'); | |
} | |
// Custom stuff for each View | |
if ($filename == 'list') { | |
$list = $this->get_list(); | |
$data = array_merge($data, array('list' => $list)); | |
} | |
// Replace [custom values] | |
foreach ($data as $key => $value) { | |
$file = str_replace("[".$key."]", $value, $file); | |
} | |
return $file; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment