qlixes

php template engine pure

Jan 7th, 2019
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.43 KB | None | 0 0
  1. // method render template engine
  2. function templates($content, $data = array(), $return = false)
  3.     {
  4.  
  5.         foreach($data as $key => $value)
  6.             $$key = $value;
  7.  
  8.         $content = array('template/header','template/topnav', $content, 'template/footer');
  9.  
  10.         ob_start();
  11.  
  12.         include 'template/header.php';
  13.  
  14.         $template = ob_get_contents();
  15.  
  16.         ob_end_flush();
  17.  
  18.         var_dump($template);
  19.  
  20.         if($return)
  21.             echo $template;
  22.         else
  23.             return $template;
  24.     }
  25.  
  26. //logic request utk render
  27.     function login()
  28.     {
  29.         $this->templates('view/login');
  30.     }
  31.  
  32. //bentuk html
  33. <!DOCTYPE html>
  34. <html lang="en">
  35.   <head>
  36.     <meta charset="utf-8">
  37.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  38.     <meta name="viewport" content="width=device-width, initial-scale=1">
  39.     <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
  40.     <title><?= $label_app_name ?></title>       <======== <$label_app_name undefined>
  41.  
  42.     <!-- Bootstrap -->
  43.     <link href="<?= asset_url('css/font-awesome.min.css') ?>" rel="stylesheet">
  44.  
  45.     <link href="<?= asset_url('css/bootstrap.min.css') ?>" rel="stylesheet">
  46.  
  47.     <link href="<?= asset_url('css/navbar.css') ?>" rel="stylesheet">
  48.  
  49. //data yg mau dikirim
  50. return array(
  51.     'label_app_name'    => "AntonSby",
  52.     'label_app_copyright'   =>  "Dashboard &copy; 2019",
  53.  
  54.     'label_btn_login'   =>  "Login",
  55.     'label_input_user'  =>  "User",
  56.     'label_input_pass'  =>  "Password",
  57. );
Advertisement
Add Comment
Please, Sign In to add comment