Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. <?php
  2.  
  3. Class TemplateLoader {
  4. public static function compile($filePath, $variables = array())
  5. {
  6. $output = NULL;
  7. if(file_exists($filePath)){
  8. // Extract the variables to a local namespace
  9. extract($variables);
  10.  
  11. // Start output buffering
  12. ob_start();
  13.  
  14. // Include the template file
  15. include $filePath;
  16.  
  17. // End buffering and return its contents
  18. $output = ob_get_clean();
  19. }
  20.  
  21. return $output;
  22. }
  23.  
  24. public static function render($filePath, $variables = array())
  25. {
  26. echo self::compile($filePath, $variables);
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement